#P477. 【例86.4】 混合背包

【例86.4】 混合背包

Description

A traveler has a backpack that can hold at most VV kilograms. There are nn items available, with weights W1W_1, W2W_2, ..., WnW_n and values C1C_1, C2C_2, ..., CnC_n. Some items can only be taken once (0-1 knapsack), some can be taken unlimited times (unbounded knapsack), and some have a maximum number of times they can be taken (bounded knapsack). Find which items to put in the backpack so that the total weight does not exceed the backpack capacity and the total value is maximized.

Input Format

The first line contains two integers: MM (backpack capacity, M200M ≤ 200) and NN (number of items, N30N ≤ 30).
Lines 22 to N+1N+1 each contain three integers WiW_i, CiC_i, and PiP_i. The first two integers represent the weight and value of each item. The third integer PiP_i indicates the type of item: if it is 00, the item can be taken unlimited times; otherwise, it represents the maximum number of times the item can be taken.

Output Format

A single line containing one number, representing the maximum total value.

Sample

10  3
2  1  0
3  3  1
4  5  4
11