Once every cell is filled, the final state contains the optimal value. The table is not an approximation or a solver trace; it is the recurrence written out. This lesson reads the whole grid as the completed computation.

highlighted = computed this step

Filled table

The full table has 5 rows and 8 columns. Why: every item prefix is paired with every capacity.

all subproblems filled\text{all subproblems filled}
Filled DP tableThe complete recomputed table has the answer in the bottom-right cell.Filled table01234567cap-00000000(1,1)01111111(3,4)01145555(4,5)01145669(5,7)01145789

Answer location

The bottom-right cell is 9. Why: it uses all items and the full capacity.

dp[n,W]=9dp[n,W]=9
Filled DP tableThe complete recomputed table has the answer in the bottom-right cell.Filled table01234567cap-00000000(1,1)01111111(3,4)01145555(4,5)01145669(5,7)01145789

Diagram note

Every entry in the table is recomputed by the knapsack recurrence. Pixel positions are rounded for layout; every number shown is exact.

the answer lives at the final state\text{the answer lives at the final state}
Filled DP tableThe complete recomputed table has the answer in the bottom-right cell.Filled table01234567cap-00000000(1,1)01111111(3,4)01145555(4,5)01145669(5,7)01145789