思路:
枚举第一个点集中起点是哪个。 因为第i个点集总和第i-1个点集和第i+1个点集相连。 我们就可以DP求出最优解了。
f[i][j]=min(f[i][j],f[i-1][k]+dis(i,j,i-1,k));
// by SiriusRen
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
int n,num[105];
double f[105][44],ans=0x3ffffff;
struct Point{int x,y;}point[105][44];
double dis(int x1,int y1,int x2,int y2){
double tempx=1.0*(point[x1][y1].x-point[x2][y2].x)*(point[x1][y1].x-point[x2][y2].x);
double tempy=1.0*(point[x1][y1].y-point[x2][y2].y)*(point[x1][y1].y-point[x2][y2].y);
return sqrt(tempx+tempy);
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%d",&num[i]);
for(int j=1;j<=num[i];j++)
scanf("%d%d",&point[i][j].x,&point[i][j].y);
}
for(int l=1;l<=num[1];l++){
for(int i=1;i<=n;i++)
for(int j=1;j<=num[i];j++)
f[i][j]=0x3ffffff;
f[1][l]=0;
for(int i=2;i<=n;i++)
for(int j=1;j<=num[i];j++)
for(int k=1;k<=num[i-1];k++)
f[i][j]=min(f[i][j],f[i-1][k]+dis(i,j,i-1,k));
for(int i=1;i<=num[n];i++)
ans=min(ans,f[n][i]+dis(n,i,1,l));
}
printf("%d
",int(ans*100));
}