#t408. 分组背包
分组背包
Grouped 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 . The items are divided into several groups; the items within the same group conflict with each other, so at most one item from each group may be chosen. 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 three integers, (knapsack capacity, ), (number of items, ), and (the largest group number, ).
Lines : each line has three integers , denoting the weight, value, and group number of each item.
Output Format
A single line with one number: the maximum total value.
Sample Input 1
10 6 3
2 1 1
3 3 1
4 8 2
6 9 2
2 8 3
3 9 3
Sample Output 1
20
Constraints
1s, 1024KiB for each test case.