Every non-base DP cell compares two exact choices: leave the current item or take it. This lesson works one cell completely. The highlighted table shows the result cell and its two predecessors.
highlighted = computed this step
Leave option
Leaving the item gives value 5. Why: this reuses the previous row at the same capacity.
leave=5
Take option
Taking the item uses previous value 4 plus item value 5, giving 9. Why: capacity is reduced by the item weight before adding its value.
take=4+5=9
Result cell
The cell value is 9. Why: the recurrence keeps the better of take and leave.
dp[3,7]=9
Diagram note
The legend identifies the result cell, the leave predecessor, and the take predecessor. Pixel positions are rounded for layout; every number shown is exact.