Alicia's Afternoon Amble
Time limit1sMemory limit256 MB
Visit all points on a bitonic tour from the leftmost hotel to the rightmost parlour and back, minimizing total Euclidean length.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Geometry, Sorting
- Solved
- No attempts yet
Problem
Alicia is staying at a hotel on the edge of town. She sets out in the morning with a list of landmarks scattered across the city. The day of sightseeing takes her through the city, past a number of locations, all the way to Pete's Polygon Pizza Parlour on the far side, where she stops for lunch. Any location she misses on the way out, she visits on the evening walk back to the hotel.
Given the locations Alicia wants to see, find the length of the shortest tour that starts at the hotel, visits every location, and returns to the hotel. Apart from the starting location, each location is visited exactly once.
The hotel is the location with the smallest x-coordinate, and Pete's Parlour is the location with the largest x-coordinate. On the way out the tour visits locations in strictly increasing order of x-coordinate until it reaches Pete's Parlour. On the way back it visits every remaining location in strictly decreasing order of x-coordinate. The distance between two locations is the Euclidean distance, and the x-coordinate of every location is distinct.
Input
The first line contains one integer , the number of locations ().
Each of the next lines contains two integers and , the coordinates of one location ().
Output
Print the total length of the tour on one line, rounded to two decimal places.
Hint

The locations and the optimal tour for the first example.