#include <bits/stdc++.h>
using namespace std;
struct Pos {
int x, y;//用结构体存储迷宫中一个格的信息
};
const int M = 100, N = 100;//迷宫最大行列数
bool vis[M][N];//访问标记数组
int m, n, cnt;//cnt计数有几条路线
int dir[4][2] = {
{0, 1}, {1, 0}, {0, -1}, {-1, 0}};//方向增量数组,四个无序
char maze[M][N];//存储迷宫地图
void dfs(Pos s, Pos t) {//参数对应起点,终点
if (s.x == t.x && s.y == t.y) {
cnt++;
return;
}
vis[s.x][s.y] = true;//起点标记为访问过,后续不能访问
for (int i = 0; i < 4; i++) {
Pos e = {s.x + dir[i][0], s.y + dir[i][1]};//可能可走的点
if (e.x < 0 || e.x == m || e.y < 0 || e.y == n)
continue;
if (vis[e.x][e.y] == true || maze[e.x][e.y] == '#')
迷宫问题之几种走法
最新推荐文章于 2022-08-30 15:28:57 发布