L440 Backpack III
Givenn_kind of items with size Aiand value Vi(each item has an infinite number available
) and a backpack with size_m. What's the maximum value can you put into the backpack?
Notice
You cannot divide item into small pieces and the total size of items you choose should smaller or equal to m.
Example
Given 4 items with size[2, 3, 5, 7]
and value[1, 5, 2, 4]
, and a backpack with size10
. The maximum value is15
.
每件物品可以去多件。所以取这行dp[i]的来算。
例子:
size | val | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | |
0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | ||
2 | 1 | 1 | 0 | 0 | 1 | 0 | 2 | 0 | 3 | 0 | 4 | 0 | 5 |
3 | 5 | 2 | 0 | 0 | 1 | 5 | 5 | 6 | 10 | 10 | 11 | 15 | 15 |
5 | 2 | 3 | 0 | 0 | 1 | 5 | 5 | 6 | 10 | 10 | 11 | 15 | 15 |
7 | 4 | 4 | 0 | 0 | 1 | 5 | 5 | 6 | 10 | 10 | 11 | 15 | 15 |
Last updated