← Back to Learn

0-1 Knapsack

Pack items to maximize total value within a weight capacity. Watch the DP table fill cell-by-cell, then backtrack to find the optimal selection.

0123456789101112w→0000000000000A0000000000000B0000000000000C0000000000000D0000000000000E0000000000000A: w=1 v=8B: w=6 v=4C: w=4 v=3D: w=8 v=8E: w=5 v=4
0/63
speed
5
items
12
capacity
0
best value
0/12
weight
items 5
capacity 12
seed ⓘ 42
setup
Initialize: 5 items, capacity 12. DP table is (6)×(13), all zeros.
complexity
O(nW)

© 2026 Dantzig. Optimisation made accessible.

Powered by HiGHS