社区讨论

为什么炸内存

B3625迷宫寻路参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@mhiyvyke
此快照首次捕获于
2025/11/03 17:58
4 个月前
此快照最后确认于
2025/11/03 17:58
4 个月前
查看原帖
CPP
#include<bits/stdc++.h>
using namespace std;
string a;
char mapp[107][107];
int n,m,vis[107][107],res[107][107];
int dfs(int x,int y){
    if(x==n-1 and y==m-1) return 1;
    if(x-1>=0 and mapp[x-1][y]=='.') {
    	if(vis[x-1][y]) return res[x-1][y];
		res[x-1][y]=dfs(x-1,y);
		vis[x-1][y]=1;
	}
    if(y-1>=0 and mapp[x][y-1]=='.') {
    	if(vis[x][y-1]) return res[x][y-1];
		res[x][y-1]=dfs(x,y-1);
		vis[x][y-1]=1;
	}
    if(x+1<n and mapp[x+1][y]=='.') {
    	if(vis[x+1][y]) return res[x+1][y];
		res[x+1][y]=dfs(x+1,y);
		vis[x+1][y]=1;
	}
    if(y+1<m and mapp[x][y+1]=='.') {
    	if(vis[x][y+1]) return res[x][y+1];
		res[x][y+1]=dfs(x,y+1);
		vis[x][y+1]=1;
	}
	return 0; 
}
signed main(){
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>a;
        for(int j=0;j<m;j++){
            mapp[i][j]=a[j];
        }
    }
    if(dfs(1,1)) cout<<"Yes";
    else cout<<"No";
    
}

回复

0 条回复,欢迎继续交流。

正在加载回复...