dfs寻路算法---迷宫问题实现

本文转载自《算法竞赛入门经典》中迷宫问题的实现源代码。谢谢作者,留着学习。

#include
#include
#define MAXN 105
int n, m, xs, ys, xt, yt;
int vis[MAXN][MAXN], fa[MAXN][MAXN], dist[MAXN][MAXN], last_dir[MAXN][MAXN], num[MAXN][MAXN];
int maze[MAXN][MAXN] = {{1,1,0,1,1},{1,0,1,1,1},{1,0,1,0,0},{1,0,1,1,1},{1,1,1,0,1},{1,1,1,1,1}};
int dx[] = {-1,1,0,0};
int dy[] = {0,0,-1,1};
char name[] = "UDLR";

int q[MAXN*MAXN];
void bfs(int x, int y) {
  int front=0, rear=0, d, u;
  u = x*m+y;
  vis[x][y] = 1; fa[x][y] = u; dist[x][y] = 0;
  q[rear++] = u;
  while(front=0 && nx=0 && ny


你可能感兴趣的:(面试算法)