#P476. 【例86.3】 完全背包问题
【例86.3】 完全背包问题
Description
There are types of items, each with a weight and a value. Each type of item can be selected multiple times (unlimited quantity). Given a backpack with maximum capacity , select items from the types (the same type can be selected multiple times) such that the total weight is less than or equal to and the total value is maximized.
Input Format
The first line contains two integers: (backpack capacity, ) and (number of item types, ).
Lines to each contain two integers and , representing the weight and value of each item type.
Output Format
A single line containing one number, representing the maximum total value.
Sample
10 4
2 1
3 3
4 5
7 9max=12