← ~/bài tập
P2005

0/1 Knapsack

Hard
// Đề bài
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.
// Đầu vào
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).
// Đầu ra
A single integer: the maximum total value.
// Gợi ý
Classic O(N*W) dynamic programming over a 1-D table.
// Ví dụ
Đầu vào ví dụ
4 5
1 1
2 6
3 8
2 5
Đầu ra ví dụ
14
// Thông tin bài tập
Độ khóHard
Tỉ lệ chấp nhận70%
Giới hạn thời gian2000 ms
Giới hạn bộ nhớ131072 KB
Được chấp nhận7