I’m trying to solve next task:
Given a set of items, each with a weight and a value, determine the knapsack minimal carrying capacity of the given total value.
For Example
Input:
item1: w = 3.4, v = 3
item2: w = 0.4, v = 1
total value = 7
Output:
We should take:
item1 x0, item2 x7
And
minimal capacity = 0 * 3.4 + 0.4 * 7 = 2.8
total value = 7
What recursive formulas should I use for general algorithm using dynamic programming? Can anyone show an example of solving this with tiny input data?
P.S. Sorry for my english.
The traditional (maximizing) knapsack algorithm should work fine. Just swap all the occurrences of
maxforminand you should be almost there. Another way to see this is using negative costs so minimizing becomes maximizing (you will need to pay special attention to the empty case though).