Here's the simplification: you don't need to track which items you've processed. Since items can repeat, the order doesn't matter.
Define as the maximum value achievable with capacity . That's it. One dimension instead of two. For each capacity, you consider all items and decide whether to add one more copy of each. Base case: (zero capacity means zero value). Understanding this concept will help you solve more complex problems.