Double Tune Euclid Travel Quotient problem is a classic dynamic programming problem. "Introduction to Algorithms (second edition)" Study Questions 15-1 and Peking University OJ2677 both appeared in this topic.
Traveler's question description: N points on a plane to determine the shortest closing journey of a connected point. The general form of the solution is NP (can be obtained in polynomial time)
J.L Bentley recommends simplifying the problem by considering only the two-tone journey (Bitonictour), which is to start from the leftmost point, strictly from left to right up to the right, and then strictly from right to left to the starting point. (b) shows the
The same 7-point shortest two-tone route. In this case, the algorithm of the polynomial is possible. In fact, there is an algorithm for determining the optimal double-alignment of the O (n*n) time.
, A is the shortest closed route, and this route is not double-tuned. B is the shortest two-tone closed route.
Solution process:
(1) Firstly, the points are arranged from small to large by x-coordinates, and the time complexity is O (NLGN).
(2) Looking for substructure: Define the path from pi to PJ: Start with Pi, right to left until P1, and then from left to right until PJ. On this path, it passes through all the points between P1 and Pmax (I,J) and only once.
In the definition D (i,j) is the shortest path that satisfies this condition. We only consider the situation of i>=j.
Also, define DIST (I,J) as the line distance between the point pi to PJ.
(3) Optimal solution: We need to ask for D (N,n).
The solution to sub-problem D (I,J) is divided into three cases:
A, when J < I-1, d (i,j) = d (i-1,j) + dist (i-1,i).
By definition, the point Pi-1 must be on the path PI-PJ, but also because of j<i-1, so the left side of Pi must be Pi-1. The above equation can therefore be derived.
B, when j = i-1, the point of the left side of the PI may be P1 to Pi-1 any one of the total.
It is therefore necessary to recursively find the smallest path:
D (i,j) = d (i,i-1) = Min{d (k,j) + dist (i,k)}, where 1 <= k <= J.
C, when J=i, the last two points on the path may be p1-pi, p2-pi ... Pi-1-pi.
So there are:
D (i,i) = Min{d (i,1) +dist (1,i),..., D (i,i-1), Dist (i-1,i)}:
"Algorithmic learning" double-tuning Euclid Travel Quotient problem (Dynamic planning) (RPM)