(Latest Revision:
Nov 21, 2021)
Solution to Knapsack Problem
============================
Total Weight ----->
obj
# wt val | 0 1 2 3 4 5 6 7 8
__________________________________________________
0 0 0 | 0* 0 0 0 0 0 0 0 0
1 2 4 | 0 0 4* 4 4 4 4 4 4
2 4 9 | 0 0 4 4 9 9 13* 13 13
3 2 5 | 0 0 5 5 9 9 14 14 18*
4 3 8 | 0 0 5 8 9 13 14 17 18*
Objects to use in optimal solution: 3 (wt=2;v=5), 2 (wt=4;v=9), and 1 (wt=2;v=4)
The sum of values of items 3, 2, and 1 is 5+9+4=18,
which is the last entry in the table, as it should be.
The sum of weights of items 3, 2, and 1 is 2+4+2=8,
which does not exceed the weight limit of 8.
============================