Dynamic Programming21 sections · 916 units
Open in Course

Unlimited to Limited

The constraint

You've seen 0/1 knapsack (each item once) and unbounded knapsack (unlimited copies). Bounded knapsack sits in between: each item has a limit kik_i on how many copies you can take. The naive approach: treat item ii as kik_i separate items and run 0/1 knapsack.

But if ki=1000k_i = 1000 for many items, this explodes. There's a clever trick using binary representation that reduces kk copies to log(k)\log(k) items. I'll show you how.