背包问题(动态规划)

要求:Given weights and values of n items, put these items in a knapsack of capacity W to get the maximum total value in the knapsack.

从这n项中获取最大值的方法:考虑这些包含着n个item的集合的所有子集,对于每个item来说无非两种情况:(1)这个item包含在最优解集合中(2)这个item没有被包含在最优解集合中

因此:最大值就是一下这两种情况的较大者
1) Maximum value obtained by n-1 items and W weight.
2) Value of nth item plus maximum value obtained by n-1 items and W minus weight of the nth item (including nth item).

If weight of nth item is greater than W, then the nth item cannot be included and case 1 is the only possibility.

reference:http://www.geeksforgeeks.org/dynamic-programming-set-10-0-1-knapsack-problem/

你可能感兴趣的:(背包问题(动态规划))