Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

请问这个枚举哪里错了

Posted by shhu at 2007-08-26 10:28:21 on Problem 3311
这个个数据我得到的是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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator