cs209 lab6


http://www.maths.nuigalway.ie/~gettrick/teach/cs209/l6.html




In this weeks lab, you should write a program in PYTHON to solve the 0/1 Knapsack problem using the dynamic programming strategy. In the 0/1 Knapsack problem, we have a bag of (weight) capacity K kilograms. We have n items of weight w(1), w(2), w(3), ... , w(n) (in Kg) and of respective values v(1), v(2), v(3), ... , v(n) (in euro). We have to decide which items to fit in to our bag to obtain maximum value. There is only one of each item, and you can also assume w(1)+w(2)+w(3)+...+w(n) > K (i.e. all the items won't fit in our bag). Write a PYTHON program to "solve" this using the dynamic programming strategy. Your program should build up the table (list of lists) of subsolutions, and not use a recursive function. Instead, just use nested loops.
Note:

Run your program on the data:
  1. WEIGHTS: 21,40,30,3,17,13,26,23,31,7,16,19
  2. VALUES: 40,70,41,6,33,39,48,34,50,14,27,37
and bag capacities 48kg, 71kg and 103kg, and submit these 3 answers with your report.

© NUI, Galway