社区讨论
样例通过,纯dfs做法 请帮帮俺
B3625迷宫寻路参与者 4已保存回复 4
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 4 条
- 当前快照
- 1 份
- 快照标识符
- @mhji4jxy
- 此快照首次捕获于
- 2025/11/04 02:56 4 个月前
- 此快照最后确认于
- 2025/11/04 02:56 4 个月前
https://www.luogu.com.cn/record/229721854
(上面应该是评测记录)
CPP#include <bits/stdc++.h>
using namespace std;
char s[101][101];
bool b[101][101] = {0};
int x[4] = {0,0,-1,1} ,y[4] = {1,-1,0,0};//移动方向
int n,m;
int tot=0;
void search(int p,int q);
int main()
{
cin >> n >> m;
for (int i=1;i<=n;i++)
for (int j=1;j<=m;j++)
cin >> s[i][j];
b[1][1] = 1;
search(1,1);
if (tot >= 1) cout << "Yes";
else cout << "No";
return 0;
}
void search(int p,int q)
{
for (int j=0;j<4;j++)
{
int xx = p + x[j];
int yy = q + y[j];
if (!b[xx][yy] && xx >0 && xx<=n && yy>0 && yy<=m && s[xx][yy] == '.') // 可以走,没走过,没越界
{
b[xx][yy] = 1;//标记已经走了
if (xx == n && yy == m)//到达终点
{
tot++;//path总数+1
}
search(xx,yy); //换成新的坐标继续搜索下去
b[xx][yy] = 0;//回溯 取消标记
}
}
}
非常感谢洛谷上愿意阅读别人代码来找问题的人 希望你们的oi路前程似锦 能看到这句话的人,你今天一定能收获满满
回复
共 4 条回复,欢迎继续交流。
正在加载回复...