Cross Country

시간 제한10초메모리 제한1024 MB

요약
n개의 선분 검문소를 1번부터 n번까지 순서대로 통과하면서 시작점에서 도착점까지 가는 최단 경로의 길이를 구한다.
난이도

어려움10점 중 9점

유형
기하, 동적 계획법, 비트 연산, 최단 경로
정답자
아직 제출이 없습니다

문제

Cross-country running is a sport in which contestants run a race on an open-air course over natural terrain. To record contestants' progress, the organisers set up RFID checkpoints that each span a line across part of the course.

A contestant has finished the race once they go through all of the checkpoints in order from 11 to nn. Crossing a checkpoint out of order conveys no advantage or penalty to a runner, as they simply have to cross it again later at the right time. Thus, for example, a runner may choose to cross a checkpoint once and then immediately cross it again in another direction if it leads to a quicker finish.

Figure C.1: Optimal running route for the course given in sample input 3.

Your objective is to find the shortest distance one has to run to finish the race, so that we can use this as the official distance of the course.

입력

  • One line containing the number of checkpoints, nn (1≤n≤161 \le n \le 16).
  • One line containing the start coordinate of the race, x_sx\_s and y_sy\_s (−106≤x,y≤106-10^6 \le x, y \le 10^6).
  • nn further lines, the iith of which contains the two integer coordinate of the iith checkpoint's endpoints, x_a_iy_ax_by_b{x\_a}\_i y\_a x\_b y\_b (−106≤x,y≤106-10^6 \le x,y \le 10^6).
  • One line containing the end coordinate of the race, x_tx\_t and y_ty\_t (−106≤x,y≤106-10^6 \le x, y \le 10^6).

All of the checkpoints have non-zero length; however, they may overlap either with each other or with the start and finish points.

출력

Output the shortest distance you can run to go visit all of the checkpoints in the right order, regardless of whether you touch some of the checkpoints multiple times or in the wrong order along the way.

The output must be accurate to an absolute or relative error of at most 10−610^{-6}.

예제3

  1. 예제 1

    입력
    2
    0 1
    10 0 10 2
    20 2 20 0
    30 1
    
    예상 출력
    30
    
  2. 예제 2

    입력
    4
    5 5
    10 1 8 -1
    12 3 13 0
    18 3 17 0
    20 1 22 -1
    25 5
    
    예상 출력
    22.80624847
    
  3. 예제 3

    입력
    3
    0 0
    3 -1 2 1
    8 0 8 1
    5 -1 5 1
    0 2
    
    예상 출력
    16.144380531