#P477. 【例86.4】 混合背包
【例86.4】 混合背包
Description
A traveler has a backpack that can hold at most kilograms. There are items available, with weights , , ..., and values , , ..., . 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: (backpack capacity, ) and (number of items, ).
Lines to each contain three integers , , and . The first two integers represent the weight and value of each item. The third integer indicates the type of item: if it is , 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 411