cs209 lab5


http://www.maths.nuigalway.ie/~gettrick/teach/cs209/l5.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(KG): 23,30,30,4,19,11,24,20,31,9,18,17,15,7
  2. VALUES(EURO): 40,66,45,7,36,31,48,32,54,14,27,25,32,14
and bag capacities 48kg, 75kg and 91kg, and submit these 3 answers with your report.

© NUI, Galway