Knapsack Simulator
Fill the 0/1 DP table cell by cell, then compare it against the fractional greedy answer.
| item / cap | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|---|
| none | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| A | · | · | · | · | · | · | · | · | · |
| B | · | · | · | · | · | · | · | · | · |
| C | · | · | · | · | · | · | · | · | · |
| D | · | · | · | · | · | · | · | · | · |
Row 0 means "no items available", so every cell is 0. Each cell (i, w) is the best value from the first i items within capacity w.
step 1 of 38
Result
- Capacity
- 8
- Best value
- —
- Items taken
- —
Each cell asks one question: is it better to skip this item, or take it and use the best solution for the remaining capacity?
Your items
| Item | Weight | Value | |
|---|---|---|---|
| A | 2 | 3 | |
| B | 3 | 4 | |
| C | 4 | 5 | |
| D | 5 | 6 |
← → to step, or use the buttons above.