d[s]为集合s配对后的最小距离和,dp[s]=min(dp[s],dp[s-{i}-{j}]+|pipj|)。
//
// main.cpp
// Richard
//
// Created by 邵金杰 on 16/10/1.
// Mail:1016427040@qq.com or jasonshaosjj@gmail.com
// Copyright © 2016年 邵金杰. All rights reserved.
//
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=20;
const int inf=1000000000;
double dist(double x,double y,double z)
{
return sqrt(x*x+y*y+z*z);
}
int x[maxn],y[maxn],z[maxn];
double dp[(1<<maxn)];
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++) scanf("%d%d%d",&x[i],&y[i],&z[i]);
for(int i=1;i<(1<<n);i++) dp[i]=inf;
dp[0]=0;
for(int s=3;s<(1<<20);s++)
{
int p=0;
while(!(s&(1<<p))) p++;
for(int j=p+1;j<20;j++)
{
if(s&(1<<j))
{
dp[s]=min(dp[s],dp[s-(1<<p)-(1<<j)]+dist(x[p]-x[j],y[p]-y[j],z[p]-z[j]));
}
}
}
printf("%.3f\n",dp[(1<<n)-1]);
return 0;
}