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