#P1757. 通天之分组背包

通天之分组背包

Description

After the 0101 knapsack came out, Xiao A became very interested. One day, Xiao A went on a trip and found that his backpack was different from the 0101 knapsack. His items can be roughly divided into kk groups, and items within the same group are mutually exclusive (you may choose at most one item from each group). Now he wants to know the maximum total value he can obtain.

Input Format

Two integers m,nm,n, indicating there are nn items in total, and the backpack can bear a maximum weight of mm.

Then nn lines follow. Each line contains 3 integers ai,bi,cia_i,b_i,c_i, representing the item's weight, value, and group index.

Output Format

One integer: the maximum total value.

45 3
10 10 1
10 5 1
50 400 2
10

Hint

0m10000 \leq m \leq 1000, 1n10001 \leq n \leq 1000, 1k1001\leq k\leq 100, ai,bi,cia_i, b_i, c_i are within the int range.

Translated by ChatGPT 5