|
沙发
楼主 |
发表于 2018-8-21 14:06:02
|
只看该作者
- #include<iostream>
- #include<cmath>
- #include<iomanip>
- using namespace std;
- int n;
- struct node
- {
- double x,y;
- }a[17];
- double ans=99999,dis[17][17];
- bool cheese[17];
- void dfs(int step,int now,double len)
- {
- if(len>=ans)return;
- if(step==n)
- {
- ans=min(ans,len);
- return;
- }
- for(int i=1;i<=n;i++)
- {
- if(cheese[i])continue;
- cheese[i]=1;
- dfs(step+1,i,len+dis[now][i]);
- cheese[i]=0;
- }
- }
- int main()
- {
- cin>>n;
- for(int i=1;i<=n;i++)
- cin>>a[i].x>>a[i].y;
- a[0].x=0;a[0].y=0;
- for(int i=0;i<=n;i++)
- for(int j=0;j<=n;j++)
- dis[i][j]=sqrt((a[i].x-a[j].x)*(a[i].x-a[j].x)+(a[i].y-a[j].y)*(a[i].y-a[j].y));
- dfs(0,0,0.0);
- cout<<fixed<<setprecision(2)<<ans<<endl;
- return 0;
- }
复制代码 |
|