Given up to 12 disjoint line-segment gates in order, find the shortest path that touches each gate in sequence.
Hard8GeometryDynamic programmingShortest pathNo attempts yetTime limit8sMemory limit512 MBThe car company Moving has developed a new ride for switchback courses. The machine moves and turns in any direction at the same speed.
To promote the ride, the company started a competition called the extreme slalom. A course of the extreme slalom consists of gates numbered from 1, and every gate is a line segment. A rider starts at the first gate and runs to the last gate, passing through or touching the gates in the order of their numbers. Passing through or touching a gate other than the current target is allowed, but it does not count.
Your team enters the next competition. Winning takes the shortest possible path. Write a program that computes the shortest length for your teammates.

An example course for the extreme slalom
The input consists of several courses.
The first line of a course holds the number of gates n (2≤n≤12). Each of the next n lines describes one gate in the order of traversal. A line holds four integers x1, y1, x2, y2 (0≤x1,y1,x2,y2≤100), the two endpoints of the gate. No two gates touch or intersect.
The last line of the input holds a single 0.
For each course, print the shortest length on its own line. Round the value to four digits after the decimal point and always print all four digits, padding with zeros. The exact answer is at least 10−5 away from a rounding boundary, so the fourth digit is determined uniquely.