rt
本人只会枚举和模拟(非退火),DP/DFS则一概不通
帮忙指出问题所在%%%
LANG:cpp
code:
#include<bits/stdc++.h>
using namespace std;
struct node {
double x,y;
} n[20];
long double FTD(double x1,double y1,double x2, double y2) {
return sqrt(pow(x1-x2,2)+pow(y1-y2,2));
}
long double JRN_min=1145141919.810;
double last_point[2];
long double JRN_cnt;
int main() {
int s;
scanf("%d",&s);
for(int i=0; i<s; i++) {
scanf("%lf%lf",&n[i].x,&n[i].y);
}
for(int i=1; i<=(1<<s) ; i++) {
last_point[0]=n[0].x;
last_point[1]=n[0].y;
for(int j=1; j<s; j++) {
JRN_cnt+=FTD(last_point[0],last_point[1],n[j].x,n[j].y);
last_point[0]=n[j].x;
last_point[1]=n[j].y;
}
if(JRN_cnt<JRN_min){
JRN_min=JRN_cnt;
}
JRN_cnt=0;
}
printf("%.2Lf",JRN_min);
return 0;
}