70分!DFS!优化过了!就是不过!
查看原帖
70分!DFS!优化过了!就是不过!
563217
luogu_orz楼主2023/7/12 22:21
本蒟蒻

在疑惑:

#include<bits/stdc++.h>
using namespace std;
int n,m;
char ch[110][110];
bool vis[110][110];
bool dfs(int x,int y){
    if(x==n&&y==m){
        return 1;
    }else{
        if(x+1<=n&&ch[x+1][y]!='#'&&!vis[x+1][y]){
            vis[x+1][y]=1;
            if(dfs(x+1,y)==true){
                return 1;
            }
        }
        if(x-1>=1&&ch[x-1][y]!='#'&&!vis[x-1][y]){
            vis[x-1][y]=1;
            if(dfs(x-1,y)){
                return 1;
            }
        }
        if(y+1<=m && ch[x][y+1]!='#' && !vis[x][y+1]){
            vis[x][y+1]=1;
            if(dfs(x,y+1)){
                return 1;
            }
        }
        if(y-1<=m && ch[x][y-1]!='#' && !vis[x][y-1]){
            vis[x][y-1]=1;
            if(dfs(x,y-1)){
                return 1;
            }
        }
        return 0;
    }
    
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>ch[i][j];
        }
    }
    if(dfs(1,1))cout<<"Yes";
    else cout<<"No";
    return 0;
}

所以我哪里写错了呢????????! 这难道不是模版吗

2023/7/12 22:21
加载中...