#P476. 【例86.3】 完全背包问题

【例86.3】 完全背包问题

Description

There are nn 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 MM, select items from the nn types (the same type can be selected multiple times) such that the total weight is less than or equal to MM and the total value is maximized.

Input Format

The first line contains two integers: MM (backpack capacity, M200M ≤ 200) and NN (number of item types, N30N ≤ 30).
Lines 22 to N+1N+1 each contain two integers WiW_i and CiC_i, 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 9
max=12