csp-s simulation test 50 (9.22) "construction (monotonous stack optimized DP)" · "vegetable (everolimus two teams ???)" * "Union (tree diameter)."

Change a couple of days, and finally T1, T3 cancer questions change over ...

Construction of T1 (monotone stack optimization DP)

The examination room only think of n * hmaxn * hmaxn of DP, Optimization segment tree look into n * hmaxn * log but apparently not positive solution

Correct answer is very monotonous stack **

Imagine the optimal situation must be higher than the two ends of the middle period as a period of flat plains filled pit, or if we pit height difference even if only a portion of the lift and certainly useless, and if the middle of the pit has been higher than the two ends, rise again and certainly not good, then the middle of the pit can be very small, it can be very long, for this model we first thought n ^ 2 * h of DP

Set the current representation of f [i] represents the current cost to the i-node and when i change the height of the node, then can be transferred to his point of fact, only higher than the height of the i-node, then we

In fact, you can consider maintaining a monotonous stack

Then for the optimal sophistication Jane h is a quadratic function of the form, and then like a direct solver, then pay attention to the scope of the solution when seeking a quadratic function, but also pay attention to whether the solution is an integer, then playing for a long time .. ........

 

 

T2 vegetables

correct? ? ? ? Then hit it, two teams of everolimus, violence is not the time complexity

 

 

T3 Union

Good question diameter of the tree, changed one night + two self-study

First on the tree has a diameter of nature:

    The most distant minimum distance of all points of the point is the midpoint of the diameter

Then this problem demolition side is certainly on the side of the diameter of friends

But we need to find the diameter of two blocks of China Unicom, but it seems we will only deal with ....... n ^ 2

However, we found that if we are on the side edge off a diameter less than a diameter of the disconnected link block must original diameter

We can carry straight diameter and two end points DP, the two arrays is obtained, respectively diameters of the two subtrees Unicom block,

Unicom block off diameter are disposed L1, L2

The diameter side, must be newly connected diameter L1, L2, (L1 / 2 ( rounded up) + L2 of / 2 (rounded up) ) + 1, the maximum

So direct judgment, then finally find out just two breakpoints, you can find out the side of the new connection

(No handling of multi-diameter, will not .....)

 

Guess you like

Origin www.cnblogs.com/Wwb123/p/11577650.html