北京XP02第二题
2026-07-19 11:06:13
发布于:河北
快过啊死手!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#include <iostream>
using namespace std;
int n, m;
char a[45][45];
bool v[45][45], f;
int d[4][2] = { {0,1},{1,0},{0,-1},{-1,0} };
void dfs(int x, int y)
{
if (f)
{
return;
}
if (x == n - 1 && y == m - 1)
{
f = 1;
return;
}
v[x][y] = 1;
for (int i = 0; i < 4; i++)
{
int nx = x + d[i][0], ny = y + d[i][1];
if (nx >= 0 && nx < n && ny >= 0 && ny < m && !v[nx][ny] && a[nx][ny] == '.')
{
dfs(nx, ny);
}
}
}
int main()
{
cin >> n >> m;
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
f = 0;
if (a[0][0] == '.')
{
dfs(0, 0);
}
if (f)
{
cout << "YES" << endl;
}
else
{
cout << "NO" << endl;
}
return 0;
}
这里空空如也















有帮助,赞一个