Given n items with weights and values, and a capacity W, the 0-1 knapsack picks a subset to maximize total value without exceeding the budget:
Form (1) is NP-complete in W's binary encoding (Karp), but the standard DP solves it in time
The runtime (2) is pseudo-polynomial — the table size depends on W itself, not on log W. For practical W in the millions, that's fast. The recurrence underlying (2) is
Knapsack is the friendly NP-complete problem: (3) gives exact answers fast on practical sizes, and an FPTAS exists — any approximation ratio (1 − ε) in time polynomial in 1/ε.