-->
当前位置:首页 > 题库

PROGRAMMING:0-1 Backpack

Luz5年前 (2021-05-10)题库471
Given n (n < = 100) items and a backpack. The weight of item I is wi, the value is VI, and the capacity of backpack is C (C < = 1000). Q: how to choose the items in the backpack to maximize the total value of the items in the backpack? When selecting the items to be loaded into the backpack, there are only two choices for each item I: loaded or not loaded. Item I cannot be loaded many times or only part of it.
###Input format:
There are n + 1 lines in total
The first line is n-value and C-value, representing n items and Backpack Capacity C;
In the next n rows, there are two data in each row, which respectively represent the weight and value of the I (1 ≤ I ≤ n) item.
###Output format:
Output the maximum total value of items loaded in the backpack.
###Input example:
Here is a set of inputs. For example:
```in
5 10
2 6
2 3
6 5
5 4
4 6
```
###Output example:
The corresponding output is given here. For example:
```out
fifteen
```







answer:If there is no answer, please comment