求调

B3625 迷宫寻路

qqbrobin @ 2024-04-07 13:44:29

#include<bits/stdc++.h>
using namespace std;
int n,m;
char a[105][105];
int f[105][105];
int fy[4]={-1,1,0,0};
int fx[4]={0,0,1,-1};
int dfs(int x,int y){
    for(int i=0;i<4;i++){
        int dx=x+fx[i];
        int dy=y+fy[i];
        if(dx>=1&&dx<=n&&dy>=1&&dy<=m&&!f[dx][dy]&&a[dx][dy]=='.'){
            if(dx==n&&dy==m){
                cout<<"Yes";
                return 0;
            }
            f[dx][dy]=1;
            a[dx][dy]='#';
            dfs(dx,dy);
        }
    }
}
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
        }
    }
    if(!dfs(1,1)){
        cout<<"No";
    }

    return 0;                       
}

by J20220912 @ 2024-05-14 13:41:11

dfs到终点返回的是1


by qqbrobin @ 2024-07-23 20:12:16

@J20220912

不对


by J20220912 @ 2024-08-12 08:48:05

@qqbrobin 那就还有问题


by qqbrobin @ 2024-08-16 21:35:57

@J20220912 问题在哪


by J20220912 @ 2024-08-17 09:33:13

dfs最好不要用int


by qqbrobin @ 2024-08-19 16:50:06

@J20220912 哦


|