60pts求救 悬关

B3625 迷宫寻路

Qiuziyi @ 2023-12-12 16:34:08

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int n,m;
char Map[110][110];
bool dp[110][110];
int Go[2][4]={1,-1,0,0,0,0,1,-1};
bool func(int x,int y){
    if(x==n && y==m) return true;
    if(x<=0 || y<=0 || x>n || y>m) return false;
    dp[x][y]=1;
    for(int i=0;i<4;i++){
        int nx=x+Go[0][i],ny=y+Go[1][i];
        if(dp[nx][ny]) continue;
        if(func(nx,ny)) return true; 
    }
    dp[x][y]=0;
}
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>Map[i][j];
            if(Map[i][j]=='#') dp[i][j]=1;
            else dp[i][j]=0;
        }
    }
    bool flag=func(1,1);
    if(flag) cout<<"Yes";
    else cout<<"No";
    return 0;
}

QAQ


by GANYUE @ 2023-12-24 20:41:35

根本看不出来啥错误,因为我是蒟蒻 (' _ ') (doge)


by Gavinbeta @ 2024-01-09 19:00:12

dp[x][y]=0;

删了

考虑这种情况

假设感叹号也能通过

4 4

. . . #

. # !#

. . . #

. . . #

你的代码会访问!2次


|