The DP table gives you the maximum value, but which items did you take? You can reconstruct by backtracking. Start at .
If , you took item . Move to iwi. If equal, you didn't take it. Move to iw. Try this on the previous example. Start at . Is ? Yes, so we didn't take item 3. Is ? No, , so we took item 2.
Now at , so we took item 1. Items taken: 1 and 2. This backtracking works for all knapsack variants. The key is checking whether the value changed.