-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAMBLE_DP_Spoj.cpp
More file actions
42 lines (36 loc) · 929 Bytes
/
Copy pathAMBLE_DP_Spoj.cpp
File metadata and controls
42 lines (36 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// AKS
#include <bits/stdc++.h>
using namespace std;
struct point{
int x;
int y;
};
double dist(point p1, point p2){
long long dx = p2.x-p1.x;
long long dy = p2.y-p1.y;
return sqrt(dx*dx + dy*dy);
}
double mindist(point* p, int n){
double ans = 1000000001.0, ends[n][n-1];
for(int j=0;j<n-1;++j){
double m = 1000000002.0;
for(int x=0; x<j;++x)
m = min(m, ends[j][x]+dist(p[x],p[j+1]));
if(m>=1000000000.0) m=dist(p[0],p[1]);
ends[j+1][j] = m;
for(int i=j+2;i<n;++i)
ends[i][j] = ends[i-1][j] + dist(p[i],p[i-1]);
}
for(int j=0;j<n-1;++j)
ans = min(ans, ends[n-1][j] + dist(p[j],p[n-1]));
return ans;
}
int main(){
int n,x;
cin>>n;
point p[n];
for(int i=0;i<n;++i) cin>>p[i].x>>p[i].y;
if(n<=1)
cout<<"0.00"<<endl;
else cout<<std::fixed<<setprecision(2)<<mindist(p,n)<<endl;
}