UVA208玄学WA求助大佬!
  • 板块题目总版
  • 楼主xibaohe
  • 当前回复2
  • 已保存回复2
  • 发布时间2023/3/17 17:47
  • 上次更新2023/10/23 21:20:19
查看原帖
UVA208玄学WA求助大佬!
601747
xibaohe楼主2023/3/17 17:47

rt,不是行末空格或ans未清零,帮助必关

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int n,m,k,g[505][505],ans;
int plan[25];
bool vis[25];
void search(int x,int step)
{
    plan[step]=x;
    if(x==k)
    {
        for(int i=1;i<=step-1;i++) cout<<plan[i]<<" ";
     cout<<plan[step];
        cout<<endl;
        ans++;
        return;
    }
    for(int i=1;i<=n;i++)
    {
        if(g[x][i]==1&&vis[i]==false)
        {
            vis[i]=true;
            search(i,step+1);
            vis[i]=false;
        }
    }
}
int main(){
int t=0;
while(scanf("%d",&k)==1)
{
    ans=0;
    memset(vis,0,sizeof(vis));
    for(int i=1;i<=500;i++)
        for(int j=1;j<=500;j++)
            g[i][j]=0;
    t++;
    while(true)
    {
            int x,y;
            scanf("%d%d",&x,&y);
            if(x==0&&y==0) break;
            g[x][y]=g[y][x]=1;
            n=max(n,max(x,y));
    }
    vis[1]=true;
    printf("CASE %d:\n",t);
    search(1,1);
    printf("There are %d routes from the firestation to streetcorner %d.\n",ans,k);
    return 0;
}
}
2023/3/17 17:47
加载中...