V(i,j)= (2)
max{V(i-1,j),V(i-1,j-wi)+vi} j>=w
2)复杂度分析:2n
三、程序伪码:
(1)Brute Force:
Algorithm MFKnapsack(capacity, values, weights, n)
// Input: A nonnegative integer n indicating the number of the frist items being
//considered and a nonnegative integer capacity indicating the knapsack’s capacity, A
array values[] indicating the values of items, A array weights[] indicating the weights
of items.
//Output: The value of an optimal feasible subset of the first i items
if d== c.size()
for (int i = 0; i != d; ++i)
if c[i] == 1
cur_weight += weights[i];
cur_value += values[i];
if cur_weight <= capacity && cur_value > max_value
max_value cur_value;
return;
(2)Dynamic Programming: