Let's trace 0/1 Knapsack with items and capacity . Build the DP table row by row.
After item 1: .
After item 2: , (take both).
After item 3: , . The answer is . We took items 1 and 2 (weights , values ). Item 3 doesn't fit with either of them. Notice how each cell considers: skip this item (keep previous value) or take it (add value, subtract weight). This is the core of all knapsack variants.