#include <iostream>
using namespace std;
//0 为可以移动 1为障碍
int map[][10] =
{
1,1,1,1,1,1,1,1,1,1,
1,0,1,1,1,0,1,1,1,1,
1,0,0,0,0,1,1,1,1,1,
1,0,1,0,0,0,0,0,1,1,
1,1,1,1,1,0,1,1,1,1,
1,0,0,0,0,0,0,0,0,1,
1,0,1,1,0,0,1,1,0,1,
1,0,0,0,0,0,0,0,0,1 };
struct point
{
int x, y;
};
point steps[100] = { 0 };
int startx = 1, starty = 1;
int endx = 5, endy = 3;
int direct[][2] = { {-1,0},{1,0},{0,-1},{0,1} };
int row = 8, col = 10;//8行10列地图
void dfs(int deep, int x, int y)
{
int i;
if (x<0 || x>row - 1 || y<0 || y>col - 1 || map[x][y] == 1)
return;
point tmp = { x,y };
steps[deep] = tmp;
if (x == endx && y == endy) {//终点
for (i = 0; i < deep+1; i++) {
printf("(%d,%d)-", steps[i].x, steps[i].y);
}
printf("\n");
return;
}
for (i = 0; i < 4; i++)
{
map[x][y] = 1;
dfs(deep + 1, x + direct[i][0],y+direct[i][1]);
map[x][y] = 0;
}
}
int main()
{
point t = { startx,starty };
dfs(0, startx, starty);
return 0;
}
(1,1)-(2,1)-(2,2)-(2,3)-(3,3)-(3,4)-(3,5)-(4,5)-(5,5)-(6,5)-(7,5)-(7,4)-(6,4)-(5,4)-(5,3)-
(1,1)-(2,1)-(2,2)-(2,3)-(3,3)-(3,4)-(3,5)-(4,5)-(5,5)-(6,5)-(7,5)-(7,4)-(7,3)-(7,2)-(7,1)-(6,1)-(5,1)-(5,2)-(5,3)-
(1,1)-(2,1)-(2,2)-(2,3)-(3,3)-(3,4)-(3,5)-(4,5)-(5,5)-(6,5)-(6,4)-(5,4)-(5,3)-
(1,1)-(2,1)-(2,2)-(2,3)-(3,3)-(3,4)-(3,5)-(4,5)-(5,5)-(6,5)-(6,4)-(7,4)-(7,3)-(7,2)-(7,1)-(6,1)-(5,1)-(5,2)-(5,3)-
(1,1)-(2,1)-(2,2)-(2,3)-(3,3)-(3,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