#t406. 混合背包
混合背包
Mixed Knapsack
Background
Special for beginners, ^_^
Problem Description
A traveler has a knapsack that can hold at most kilograms. Now there are items with weights and values . 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, (knapsack capacity, ) and (number of items, ).
Lines : line has three integers . The first two integers are the weight and value of each item. If the third integer is , the item can be taken any number of times; otherwise it is the maximum number 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 copy of the first item and copies of the third item.