Vijos1404 in distress

Source: Internet
Author: User

Question:
Here is a number axis and M line segment. the I-th line segment covers the [Li, Ri] range. You need to select it at the cost of Ci. Select the line segment with the minimum cost so that each segment in the [L, R] is overwritten.

This topic is actually an example of Data Structure Optimization DP ..
But here we turn it into a graph theory problem. Solve it with simple knowledge.
First, we need to consider modeling.
If we regard each point on a line segment as a point on the graph, then for each line segment, it is equivalent to connecting a CI directed edge from Li to ri.
At the same time, we consider that we need to retain its line segment meaning, that is to say, these points between Li and RI should arrive at each other, and the cost should be CI.
So we can for each point I, point I-1 to a price of 0 side.
As a result, we find that the problem becomes: whether a path exists can be used from the start point to the end point, with the minimum cost ..
That is, it becomes the bare shortest path.
In addition, we found that if there is a line segment Li to RI, we just need to go to the position of the Li-1, that is, the side we actually connect is from Li-1 to RI, pay attention to this, no problem.

Vijos1404 in distress

Related Article

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.