Solve unbounded knapsack (unlimited reuse) via DP
You are given items, a list of [weight, value] pairs, and a knapsack capacity. Unlike 0/1 knapsack, every item type may be taken any number of times, and the copies are unlimited.
Return the largest total value of any multiset of items whose total weight is at most capacity.
Each item has a positive integer weight and a non-negative integer value. Reusing an item means taking another identical copy, so a type with weight w can be taken at most floor(capacity / w) times. If no item fits, or the item list is empty, the answer is 0.
Two facts make the problem well defined. The value of an empty selection is zero, and adding an item never decreases the value because all values are non-negative. The optimum therefore always exists and is finite.
Solve unbounded knapsack (unlimited reuse) via DP
You are given `items`, a list of `[weight, value]` pairs, and a knapsack capacity. Unlike 0/1 knapsack, every item type may be taken any number of times, and the copies are unlimited.