You are on page 1of 2

//SARTHAK AGARWAL

#include <bits/stdc++.h>
#define fast_io ios_base::sync_with_stdio(false);//cin.tie(0);
#define ll long long
#define MOD 1000000007
#define PI 3.1415926535897
#define pb push_back
#define mp make_pair
#define REP(i,n) for(i=0;i<n;i++)
#define FOR(i,n) for(i=1;i<=n;i++)
#define all(c) c.begin(),c.end()
#define CLEAR(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,-1,sizeof(a))
#define pi pair<int,int>
#define pii pair<int,pi>
#define F first
#define S second
using namespace std;
double dp[1<<18],dist[18][18];
int main()
{
fast_io;
int n,i,x[18],y[18],j,k,mask;
cin>>n;
n*=2;
REP(i,n)
{
cin>>x[i]>>y[i];
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
dist[i][j]=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
}
}
for(i=0;i<(1<<n);i++)
{
dp[i]=1e9;
}
dp[0]=0;
//i is a bit combination of all points
//j and k will be the two new point not in i currently
for(i=0;i<(1<<n);i++)
{
if(dp[i]>1e8)
{
continue;
}
for(j=0;j<n;j++)
{
if(!(i&(1<<j)))
{
for(k=j+1;k<n;k++)
{
if(i&(1<<k))
{
continue;

}
mask=(i|(1<<k)|(1<<j));
dp[mask]=min(dp[mask],dp[i]+dist[j][k]);
}
}
}
}
cout.precision(6);
cout<<fixed<<dp[(1<<n)-1];
return 0;
}

You might also like