Dynamic Programming21 sections · 916 units
Open in Course

Bounded Knapsack - Problem Statement

Classic variation

You have nn item types. Item ii has weight wiw_i, value viv_i, and quantity limit kik_i. Find the maximum value you can fit in a knapsack of capacity WW.

For example: items [(w=2,v=3,k=3),(w=3,v=4,k=2)][(w=2, v=3, k=3), (w=3, v=4, k=2)] with capacity W=10W=10. You can take up to 3 of the first item and up to 2 of the second. The simple solution adds another loop over quantities, but that's O(n×W×k)O(n \times W \times k). When kk is large, this times out.