← ~/試題
P2005

0/1 Knapsack

Hard
// 描述
There are N items, each with a weight and a value. Choose a subset whose total weight does not exceed W so that the total value is maximized.
// 輸入格式
The first line contains two integers N and W (1 <= N <= 1000, 1 <= W <= 1000). Each of the next N lines contains two integers w_i and v_i (1 <= w_i, v_i <= 1000).
// 輸出格式
A single integer: the maximum total value.
// 提示
Classic O(N*W) dynamic programming over a 1-D table.
// 樣例
輸入樣例
4 5
1 1
2 6
3 8
2 5
輸出樣例
14
// 題目資訊
難度Hard
通過率70%
時間限制2000 ms
記憶體限制131072 KB
通過7