#t406. 混合背包

混合背包

Mixed Knapsack

Background

Special for beginners, ^_^

Problem Description

A traveler has a knapsack that can hold at most VV kilograms. Now there are nn items with weights W1,W2,…,WnW_1, W_2, \dots, W_n and values C1,C2,…,CnC_1, C_2, \dots, C_n. Some items can be taken only once (0/1 knapsack), some can be taken an unlimited number of times (unbounded knapsack), and some can be taken at most a limited number of times (bounded knapsack). Solve which items to put into the knapsack so that the total cost does not exceed the knapsack capacity and the total value is maximized.

Input Format

The first line has two integers, MM (knapsack capacity, M≤200M \le 200) and NN (number of items, N≤30N \le 30).

Lines 2…N+12 \dots N+1: line ii has three integers Wi,Ci,PiW_i, C_i, P_i. The first two integers are the weight and value of each item. If the third integer is 00, the item can be taken any number of times; otherwise it is the maximum number PiP_i of copies that can be taken.

Output Format

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

Sample Input 1

10 3
2 1 0
3 3 1
4 5 4

Sample Output 1

11

Constraints

1s, 1024KiB for each test case.

Take 11 copy of the first item and 22 copies of the third item.