(Latest Revision:
Nov 21, 2022)
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 5 6 | 0 0 4* 4 4 6 6 10 10
3 4 5 | 0 0 4* 4 5 6 9 10 10
4 1 4 | 0 4 4 8* 8 9 10 13 14
5 5 7 | 0 4 4 8 8 9 11 13 15*
Objects to use in optimal solution: 5 (wt=5;v=7), 4 (wt=1;v=4), and 1 (wt=2;v=4)
The sum of values of items 5, 4, and 1 is 7+4+4=15,
which is the last entry in the table, as it should be.
The sum of weights of items 5, 4, and 1 is 5+1+2=8,
which does not exceed the weight limit of 8.
============================