关于c++ 迷宫问题!!!

来源:百度知道 编辑:UC知道 时间:2024/05/04 10:53:54
我想利用递归实现迷宫问题,但是我不知道怎么才能找到并打印出所有的迷宫路线,我现在只能找到一条路线,要怎么编才能打印出所有迷宫路线呢?
如果知道的 请把程序写一下参考。。谢谢,关键是如何找出所有的路线.而不是一条.递归我会了.就是如何找出所有路线有问题

回朔法

/* 迷宫问题的递归算法*/
#include <stdio.h>
#include <stdlib.h>
#define M 8
#define N 11
/* 迷宫maze[M][N]中求从入口maze[x1][y1]到出口maze[x2][y2]的一条路径 */
/* 其中 1<=x1,x2<=M-2 , 1<=y1,y2<=N-2 */
int mazePath(int* maze[], int* direction[], int x1, int y1, int x2, int y2) {
int k,g,h;
for (k = 0; k < 4; k++) {
g = x1 + direction[k][0];
h = y1 + direction[k][1];
if (g == x2 && h == y2 && maze[g][h] == 0) { /* 找到路径*/
printf("The revers path is:/n");
printf("the node is: %d %d/n",x2,y2);
printf("the node is: %d %d/n",x1,y1);
return 1;
}
if(maze[g][h] == 0) {
maze[g][h] = 2;
if (mazePath(maze, direction, g, h, x2, y2) == 1) {/*如能找到路径*/
printf(&quo