#P1064. [NOIP 2006 提高组] 金明的预算方案
[NOIP 2006 提高组] 金明的预算方案
Description
Jinming is very happy today because his family is about to receive the keys to their new home, which has a spacious room just for him. What makes him even happier is that his mother told him yesterday: “You can decide what to buy and how to arrange your room, as long as it doesn’t cost more than yuan.” Early this morning, Jinming started budgeting. He divides the items he wants to buy into two categories: main items and accessories. Accessories belong to a specific main item. The table below shows some examples of main items and accessories:
| Main Item | Accessory |
|---|---|
| Computer | Printer, scanner |
| Bookcase | Books |
| Desk | Desk lamp, stationery |
| Office chair | None |
To buy an item classified as an accessory, you must first buy its corresponding main item. Each main item can have , , or accessories. Each accessory corresponds to one main item, and accessories do not have accessories of their own. Jinming wants to buy many things, and surely the total will exceed yuan. So he assigns an importance level to each item, divided into levels represented by integers to , with level being the most important. He also found the price of each item on the Internet (all prices are multiples of yuan). He wants to maximize the sum of the product of price and importance for the selected items without exceeding yuan.
Let the price of the -th item be and its importance be . Suppose items are selected, with indices . The target sum is:
$$v_{j_1} \times w_{j_1}+v_{j_2} \times w_{j_2}+ \dots +v_{j_k} \times w_{j_k}$$Please help Jinming design a shopping list that meets the requirements.
Input Format
The first line contains two integers, the total budget and the number of items .
For lines to , each line contains three integers. On the -th line, the integers , , denote the price, importance, and the index of its main item for the -th item, respectively. If , it means the item itself is a main item.
Output Format
Output a single integer on one line representing the answer.
1000 5
800 2 0
400 5 1
300 5 1
400 3 0
500 2 0
2200
Hint
Constraints
For all test points, it is guaranteed that , , , , , and the answer does not exceed .
NOIP 2006 Senior, Problem 2.
Translated by ChatGPT 5
京公网安备 11011102002149号