Bai_cen @ 2024-02-11 11:10:36
#include <bits/stdc++.h>
using namespace std;
int n, m;
char t[114][514];
bool vis[114][514], f = 0;
int dx[] = {-1, 1, 0, 0}, dy[] = {0, 0, -1, 1};
void dfs(int x, int y){
// cout << x << " " << y << endl;
if (x == n && y == m){
f = 1;
return;
}
for (int i = 0; i < 4; i++){
int nx = x + dx[i], ny = y + dy[i];
// cout << t[nx][ny] << endl;
if (nx < 1 || nx > n || ny < 1 || ny > n) continue;
if (vis[nx][ny] == 1 || t[nx][ny] == '#') continue;
vis[nx][ny] = 1;
dfs(nx, ny);
}
}
int main(){
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
cin >> t[i][j];
vis[1][1] = 1;
dfs(1, 1);
if (f == 1) cout << "Yes";
else cout << "No";
return 0;
}
评测记录
by gjc1108 @ 2024-02-11 11:20:56
@guguBridovo
好家伙,给我看了半天
是ny>m,你写成>n了
by Bai_cen @ 2024-02-11 11:23:08
@gjc1108 谢谢!
by Bai_cen @ 2024-02-11 11:23:38
@gjc1108 已AC,已关