#t404. 完全背包问题

完全背包问题

Unbounded Knapsack

Background

Special for beginners, ^_^

Problem Description

There are nn kinds of items, each with a weight and a value. The quantity of each kind is unlimited. There is also a knapsack with maximum load MM. Choose some items from the nn kinds (the same kind may be chosen multiple times) so that their total weight is at most MM and their total value is maximized.

Input Format

First line: two integers, MM (the knapsack capacity, M≤200M \le 200) and NN (the number of item kinds, N≤30N \le 30).

Lines 2…N+12 \dots N+1: each line has two integers Wi,CiW_i, C_i, the weight and value of each item.

Output Format

A single line with one number: the maximum total value.

Sample Input 1

10 4
2 1
3 3
4 5
7 9

Sample Output 1

max=12

Constraints

1s, 1024KiB for each test case.