[SDOI2017] apple tree problem solution

First, the question is intended to observe, it can be found in the longest chain followed by a point, some better results.
In other words, you can choose a free longest chain, after a normal election.
We choose the longest chain enumeration, and then calculate the optimal solution part of the rest.
Part 4:
1, each point on the chain are selected from the group a.
2, the rest of the chain.
3, the left chain.
4, the right chain.

1 can be directly calculated.
So, we need to make the tree backpack, and then the remaining three by merging some way.
We know that in this issue, the two merged backpack \ (O (k) \) is;
but three or more is \ (O (k ^ 2) \) can not afford.
So, we can only put two of merger, so that only included in the calculation of the two.
Can be found, 3 and 4 are normal tree backpack, and 2 is a greedy problem.
However, we do not have time to sort the point in the chain, and then select greedy.
Therefore, only the 2 to normal tree knapsack problem.
Think of it this: the election will have to choose x fx, x choose the second option will have the first x.
So, we can be greater than the split point 1, and split into 1 a-1. Even the father-son relationship.
Not difficult to find, so we only need to merge the two 3,4.

First consider how the tree backpack:

There are two kinds of tree backpack achieved: dp and the combined dfs dfs sequence.
Since a plurality of each node on this problem, so before \ (O (nk) \) analysis does not apply, the complexity is \ (O (NK ^ 2) \) , clearly out.
Moreover, the complexity of the merger of the bottleneck at least backpack \ (O (k ^ 2) \) , this is a convolution max, can not be optimized.
Therefore, this method does not work.

However, since we do not need to know the information to select the child nodes of each node (such as how much each point selected sub-tree node),
it can be considered dp on dfs sequencing algorithm.

This algorithm is the number of states \ (O (nk) \) , and is equivalent to gradually add, not merged backpack.
During the addition a multiple backpack, it can be monotonous queue optimization.

pit

Guess you like

Origin www.cnblogs.com/lnzwz/p/11517807.html