loj#P160. 树形背包
树形背包
Description
There're items numbered from , each item with a weight and a value . The knapsack's capacity is .
Some items could be selected only after a specific item have been put into the knapsack, or in other words, some items depend on others.
- means item depends on item , you cannot choose item until you put item into the knapsack.
- means item does not depends on any other items.
It's guaranteed that each item depends on no more than one item. All the dependency relationships are vaild, no loop.
Maximize the sum of the values of the items in the knapsack so that the sum of the weights is no more than the knapsack's capacity.
Input
Output
A single integer, represents your answer.
7 0
3 4 5 3 0 7 0
1 2 2 1 1 2 2
1 1 2 3 1 1 2
0
7 4
3 4 5 3 0 7 0
1 2 2 1 1 2 2
1 1 2 3 1 1 2
6
10 6
0 1 1 1 2 3 4 5 6 7
1 1 2 2 3 1 2 2 3 1
0 1 1 1 1 1 1 1 1 1
3
13 3
0 1 1 1 3 3 0 0 8 9 10 8 10
1 1 1 1 1 1 1 1 1 1 1 1 1
2 16 32 512 2048 4096 4 1 8 64 1024 128 256
4130
13 25
0 1 1 1 3 3 0 0 8 9 10 8 10
5 6 4 3 7 5 4 7 3 6 5 6 6
0 2 1 2 3 3 3 0 1 2 4 3 2
10
Limits And Hints
.
Subtask id | pts | Additional Constraints | Dependencies | ||
---|---|---|---|---|---|
1 | 1 | 21 | 25 | Bare-root Forest | |
2 | 2 | 22 | 26 | A Single Tree | |
3 | 3 | 23 | 27 | Flower | |
4 | 4 | 24 | 28 | A Forest | 2 |
5 | 5 | 100 | 120 | A Single Tree | 1, 3, 4 |
6 | 10 | 200 | 250 | Forest, | 5 |
7 | 10 | 200 | Forest, | ||
8 | 10 | 250 | Forest | 6, 7 | |
9 | 15 | 400 | 500 | 8 | |
10 | 20 | 7500 | 8000 | Forest | 9 |
11 | 10 | 50000 | 1200 | 10 | |
12 | 10 | 1000 | 60000 |