标签:小数 == 内存 freopen -128 int default atom 依次
★★☆ 输入文件:linec.in
输出文件:linec.out
简单对比
时间限制:1 s 内存限制:256 MB
/* ans[sta][i]点的集合为sta,且最后一个点是i的最短路 */ #include<cmath> #include<cstdio> #include<iostream> using namespace std; int n,num1[1<<20]; double x[21],y[21],dis[21][21],ans[1<<20][21]; int main(){ //freopen("Cola.txt","r",stdin); freopen("linec.in","r",stdin);freopen("linec.out","w",stdout); scanf("%d",&n); for(int i=1;i<=n;i++)scanf("%lf%lf",&x[i],&y[i]); for(int i=1;i<=n;i++) for(int j=1;j<=n;j++){ if(i==j)continue; dis[i][j]=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])); } for(int i=0;i<=n;i++)num1[1<<i]=i+1; for(int i=1;i<(1<<n);i++){ if(!num1[i]){ for(int j=i;j;j-=j&-j){ ans[i][num1[j&-j]]=0x3f3f3f3f; for(int k=i-(j&-j);k;k-=(k&-k)) if (ans[i][num1[j&-j]]>ans[i-(j&-j)][num1[k&(-k)]]+dis[num1[j&-j]][num1[k&-k]]) ans[i][num1[j&-j]]=ans[i-(j&-j)][num1[k&(-k)]]+dis[num1[j&-j]][num1[k&-k]]; } } } double Ans=0x7fffffff; for(int i=1;i<=n;i++)Ans=min(Ans,ans[(1<<n)-1][i]); printf("%.2lf",Ans); }
标签:小数 == 内存 freopen -128 int default atom 依次
原文地址:http://www.cnblogs.com/thmyl/p/7717600.html