cs209 lab7


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




A more general version of the 0/1 Knapsack Problem covered in lectures and in last weeks lab is the Bounded Knapsack Problem. In the Bounded Knapsack Problem, there are a number of copies of each item. In particular, we have n different item types, i=1,2,3,...,n, with q(1), q(2), q(3), ... , q(n) numbers of each item, weights w(1), w(2), w(3), ... , w(n) (kg) and values v(1), v(2), v(3), ... , v(n) (kiloEuro). (So: The total number of actual items is q(1)+q(2)+q(3)+...+q(n)). 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,19,26,23,31,7,16,18
  2. VALUES: 40,70,41,6,33,39,48,34,50,15,29,37
  3. QUANTITIES: 3,4,2,5,1,1,4,1,3,2,3,6
and bag capacities 50kg, 80kg and 110kg, and submit these 3 answers with your report.

© NUI, Galway