A table on the mill’s big board filled cell by cell: the truck’s best load (0/1 knapsack) and the fewest coins of change, each cell’s choice and the answer…
Why it matters
DP is behind text diffs, spelling correction (edit distance), routing, scheduling, compression, and many interview questions. The usual mistakes: a greedy shortcut that is sometimes wrong, recursion with no notes that blows up, and a forgotten base case that makes the whole table wrong.
The key idea
Every cell worked out once, from the small ones
Common mistakes
Greedy gives more coins The biggest coin first is only right for some coin systems. For coins [1, 3, 4] and 6, greedy gives 4 + 1 + 1, the table gives 3 + 3. Use DP: dp[a] = 1 + min(dp[a − coin]).
Recursion slow on modest input With no notes, the same sub-problems are worked out again and again: calls grow exponentially. Keep the answers (a memo, a Map) or fill a table from the bottom: each sub-problem once.
The table gives a plainly wrong answer Check the base case. Without dp[0] = 0, every cell is built from ∞ and stays ∞; with a wrong base, the error spreads through the whole table.
Try it in this playground
The truck’s load Fill the load table until its load is read back onto the truck.
Change Switch to change and fill its table until the coins are read back.
Greedy loses Run to the end on a problem where the greedy way gives a worse answer.
Recursion blows up Run to the end with values that push plain recursion past 10,000 calls.