标签:iostream 状压dp 开始 close asp const algorithm tin blank
http://172.20.6.3/Problem_Show.asp?id=1384
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 #include<cmath> 6 using namespace std; 7 const int maxn=1<<25; 8 int n,x,y; 9 int a[20][2]={}; 10 double f[(1<<16)+10][20]={}; 11 int vis[20]={}; 12 double ans=(1<<30); 13 int main(){ 14 scanf("%d",&n);int x,y; 15 for(int i=0;i<n;i++){ 16 scanf("%d%d",&a[i][0],&a[i][1]); 17 }scanf("%d%d",&x,&y); 18 int ma=1<<n; 19 for(int i=1;i<ma;i++){ 20 for(int j=0;j<n;j++){ 21 f[i][j]=1.0*maxn; 22 } 23 } 24 int x1,x2;double y1,y2,wtf; 25 for(int i=0;i<n;i++){ 26 x1=1<<i; 27 y1=(double)abs(a[i][0]-x);y2=(double)abs(a[i][1]-y); 28 wtf=sqrt((double)y1*y1+y2*y2); 29 f[x1][i]=wtf; 30 }int wt=1; 31 for(int i=1;i<ma;i++){ 32 if(i==wt){wt*=2;continue;} 33 for(int j=0;j<n;j++){ 34 x1=1<<j;if((x1|i)!=i)continue; 35 for(int w=0;w<n;w++){ 36 x2=1<<w; 37 if((x2|i)!=i||w==j)continue; 38 y1=(double)abs(a[j][0]-a[w][0]);y2=(double)abs(a[j][1]-a[w][1]); 39 wtf=sqrt((double)y1*y1+y2*y2); 40 if(f[i-x1][w]+wtf-f[i][j]<0){ 41 f[i][j]=f[i-x1][w]+wtf; 42 } 43 } 44 } 45 }double ans=maxn; 46 for(int i=0;i<n;i++){ 47 if(f[ma-1][i]<ans)ans=f[ma-1][i]; 48 } 49 printf("%.2f",ans); 50 return 0; 51 }
标签:iostream 状压dp 开始 close asp const algorithm tin blank
原文地址:http://www.cnblogs.com/137shoebills/p/7787019.html