Dynamic Programming21 sections · 916 units
Open in Course

Knapsack 2 - Why Weight-Based DP Fails

The constraint trap

Let's do the math. With W=109W = 10^9, a DP table of size n×Wn \times W would need 100×109=1011100 \times 10^9 = 10^{11} entries. That's 100100 billion operations and hundreds of gigabytes of memory. No amount of improvement saves you. The problem isn't implementation; it's the approach.

You need to change what you're computing. Look at the values instead: vi1000v_i \le 1000 and n100n \le 100. Maximum total value is at most 100,000100{,}000. That's a much smaller dimension.