Ultraviolet A 1484 Alice and Bob's trip (tree DP)

Source: Internet
Author: User

From http://blog.csdn.net/shuangde800


Source:
UV HDU


Question

A tree with N nodes numbered 0 ~ N-1, vertex is 0
Each edge has a weight.
Alice and Bob start at the vertex and go down to the leaf node.
For the first time, Bob chooses the child node to go to, and for the second time, Alice takes turns...
Each time you walk through an edge, you will get the corresponding weight. Bob wants the larger the total weight of the path, the better, and Alice wants the smaller the better.
Each time they choose the optimal solution.
The final total weight must be within the range [L, R.
What is the maximum weight Bob wants in the end?

Ideas

F (u, 0) indicates the maximum value of the U point selected by Bob.

F (u, 1) indicates the maximum value of the U point selected by Alice.

Tot (u) indicates the sum of the weights from vertex to vertex I.

W (u, v) indicates the Edge Weight of the connection points u and v.

So
F (u, 0) = max {f (V, 1) + W (u, v) | V is the son node of U & L <= f (V, 1) + W (u) + Tot (u) <= r}
F (u, 1) = min {f (v, 0) + W (u, v) | V is the son node of U & L <= f (v, 0) + W (u) + Tot (u) <= r}

The final answer is F (0, 0)


In addition, when submitting an HDU question, C ++ can be used for AC, but G ++ is used for TLE. I don't know why.

Submissionerr is used to submit the request in the request, and then ask the administrator of the request, saying that the system problem cannot be solved for the time being...

Code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.