标签:const namespace printf i++ ble ems its 暴搜 mem
传说这种题叫什么旅行商问题?
这题卡记搜和暴搜,注意一下……
#include<bits/stdc++.h> using namespace std; const int maxn=20; int n,vis[maxn]; double x[maxn],y[maxn],ans,dist[maxn][maxn]; double dp[1<<16][maxn]; int main(){ cin>>n; for(int i=1;i<=n;i++) cin>>x[i]>>y[i]; x[0]=y[0]=0; for(int i=0;i<=n;i++) for(int 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])); memset(dp,127,sizeof(dp)); for(int i=0;i<=n;i++) dp[(1<<(n+1))-1][i]=0; for(int S=(1<<(n+1))-2;~S;S--) for(int i=0;i<=n;i++) for(int j=0;j<=n;j++) if(!(S&1<<j))dp[S][i]=min(dp[S][i],dp[S|1<<j][j]+dist[i][j]); printf("%.2lf\n",dp[0][0]); return 0; }
深深地感到自己的弱小。
标签:const namespace printf i++ ble ems its 暴搜 mem
原文地址:https://www.cnblogs.com/syzf2222/p/12424093.html