| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
请问这个枚举哪里错了这个个数据我得到的是38,答案是37
8
0 1 2 3 4 5 6 7 8
1 0 2 3 4 5 6 7 8
1 2 0 3 4 5 6 7 8
1 2 3 0 4 5 6 7 8
1 2 3 4 0 5 6 7 8
1 2 3 4 5 0 6 7 8
1 2 3 4 5 6 0 7 8
1 2 3 4 5 6 7 0 8
1 2 3 4 5 6 7 8 0
#include<cstdio>
#include<algorithm>
using namespace std;
int d[20][20],path[20],mint;
int main()
{
int n,i,j,s,t;
while(scanf("%d",&n)&&n)
{
for(i=0;i<=n;i++)
for(j=0;j<=n;j++)
scanf("%d",&d[i][j]);
for(i=0;i<=n;i++)
for(s=0;s<=n;s++)
for(t=0;t<=n;t++)
d[s][t]=min(d[s][t],d[s][i]+d[i][t]);
for(i=0;i<=n;i++)
path[i]=i;
path[n+1]=0;
mint=0x3fffffff;
while(next_permutation(path+1,path+n+1))
{
s=0;
for(i=0;i<=n;i++)
s+=d[path[i]][path[i+1]];
mint=min(mint,s);
}
printf("%d\n",mint);
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator