Dynamic Programming21 sections · 916 units
Open in Course

Weight-Based to Value-Based

When weights explode

Your O(nW)O(n \cdot W) solution works great when WW is small. But what if W=109W = 10^9? You can't create an array of size 10910^9. The solution crashes before it starts.

But notice something: even with huge weights, the total value might be bounded. If n=100n = 100 and each value is at most 10001000, the maximum possible value is 100,000100{,}000. What if you flipped the problem? Instead of "max value for this weight," ask "min weight for this value." That's the observation for the next problem.