Given the weights and values of
n
items to be kept in a knapsack of capacity
capacity
. Write a program to get the
maximum total value
in the knapsack.
Problem Note
-
Items are given as
(value, weight)
pairs i.e.
(val, wt)
.
Example 1
Input: Items[] = [ [6, 1], [10, 2], [12, 3] ]
Knapsack Capacity(capacity) = 5
Output: Maximum possible value = 24
Explanation: By taking full items of 1 kg, 2 kg and 2/3rd of last item of 3 kg. Total value = 6 + 10 + 12*2/3 = 24