#t408. 分组背包

分组背包

Grouped 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. 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, VV (knapsack capacity, V≤200V \le 200), NN (number of items, N≤30N \le 30), and TT (the largest group number, T≤10T \le 10).

Lines 2…N+12 \dots N+1: each line has three integers Wi,Ci,PiW_i, C_i, P_i, 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.