Every non-base DP cell compares two exact choices: leave the current item or take it. This lesson works one cell completely so the recurrence becomes an interpretable argument, not just a formula. The highlighted table shows the result cell and its two predecessors.

highlighted = computed this step

Leave option

Leaving the item gives value 5. Why: if the current item is not chosen, the best value cannot depend on it at all. The recurrence therefore looks to the previous row at the same capacity, which means the same bag space is available but fewer items may be used.

leave=5\text{leave}=5
Take or leave cellThe highlighted cell and predecessors are recomputed from the DP table.Worked recurrence01234567cap-00000000(1,1)01111111(3,4)01145555(4,5)01145669(5,7)01145789resultleave (skip item i)take (item i)

Take option

Taking the item uses previous value 4 plus item value 5, giving 9. Why: taking an item spends capacity before earning value. The lookup goes to the previous row so the same item is not counted again, and it goes to the reduced capacity because the item now occupies part of the bag.

take=4+5=9\text{take}=4+{}5=9
Take or leave cellThe highlighted cell and predecessors are recomputed from the DP table.Worked recurrence01234567cap-00000000(1,1)01111111(3,4)01145555(4,5)01145669(5,7)01145789resultleave (skip item i)take (item i)

Result cell

The cell value is 9. Why: every feasible subset for this prefix either takes the current item or leaves it, so the better of those two exact cases is the whole answer for the cell. The highlighted cell is therefore a local certificate for one subproblem.

dp[3,7]=9dp[3,7]=9
Take or leave cellThe highlighted cell and predecessors are recomputed from the DP table.Worked recurrence01234567cap-00000000(1,1)01111111(3,4)01145555(4,5)01145669(5,7)01145789resultleave (skip item i)take (item i)

Diagram note

The legend identifies the result cell, the leave predecessor, and the take predecessor. Those three roles are the whole recurrence in miniature: compare the old best value with the value of taking the item after freeing the required capacity. No estimate or search shortcut is hidden in the picture. Pixel positions are rounded for layout; every number shown is exact.

one cell is a max of two exact integers\text{one cell is a max of two exact integers}
Take or leave cellThe highlighted cell and predecessors are recomputed from the DP table.Worked recurrence01234567cap-00000000(1,1)01111111(3,4)01145555(4,5)01145669(5,7)01145789resultleave (skip item i)take (item i)