Dynamic programmingAnimated
Unbounded Knapsack
Like 0/1 knapsack but each item can be used unlimited times.
Time
O(n · W)
Extra space
O(W)
Use it for
Cutting and coin-style problems.
How it works
- Like 0/1 knapsack, but every item can be used any number of times.
- best(c) = the best value with capacity c. best(0) = 0.
- For each capacity try every item that fits: best(c) = max over items of value + best(c − weight).
- Because the same item may be reused, a single row is enough. O(capacity × items).
Watch it run
Loading animation…