(Latest Revision: Nov 21, 2022)

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   
 2   5   6   |   0   
 3   4   5   |   0   
 4   1   4   |   0   
 5   5   7   |   0
Let me know if you have questions about how such problems are solved. The algorithm is covered in section 6.4.

Directions For Submitting Solution:

You will e-mail me your homework solution.
Below is a sample of the information I want in your e-mail. It shows what the information would be for an example problem. You must give me the same kind of information, in the same format, for your assigned problem.

============================
                   Total Weight ----->
obj
 #  wt val   |  0   1   2   3   4   5   6   7
_____________________________________________
 0  0   0   |   0*  0   0   0   0   0   0   0
 1  1   2   |   0*  2   2   2   2   2   2   2
 2  4   9   |   0   2   2   2   9* 11  11  11
 3  3   7   |   0   2   2   7   9  11  11  16*
 4  2   3   |   0   2   3   7   9  11  12  16*

Objects to use in optimal solution: 3 (wt=3;v=7), 2 (wt=4;v=9)
The sum of values of items 3 and 2 is 7+9=16, which is the last entry in the table, as it should be.
The sum of weights of items 3 and 2 is 3+4=7, which does not exceed the weight limit of 7.
============================