Defined
When
the weight of each item
item is
$$
max ∑{i in I}v_iw_i s.t. ∑{i in I}v_iw_ile Wxin mathbb{N}(forall
in I)
$$ where
represents the number of items to be placed in the knapsack.
solution
The problem is that if you perform a total search, you will try two options of "select or not select items" for the number of items, and the computational complexity is
Become. where
- If "no items can be selected" or "the maximum weight is
", the sum of the values of the selected items is because there are no items to pack. - If the weight of the item
exceeds , the item cannot be added, so the total value is the maximum value of the item up to one previous subscript limit. - If the weight of item
does not exceed , the item should be the least less, either the maximum value of adding the item or the maximum value of the addition of the item.
It shows that. The pseudocode is as follows. The maximum value of the sum is V(| I|, W). In addition, enumerating the selected items requires the addition of code.