POJ 3984 迷宫问题

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <algorithm>
 5 #define CL(x, y) memset(x, y, sizeof(x))
 6 using namespace std;
 7 const int MAX = 5;
 8 int N, i, j, a, b, flag;
 9 int chessboard[MAX*MAX], used[MAX][MAX],maze[MAX][MAX];
10 int Move[4][2]= {{0,1},{1,0},{0,-1},{-1,0}};
11 void DFS(int x, int y, int z);
12 int main()
13 {
14     for(i = 0; i < MAX; i++)
15         for(j = 0; j < MAX; j++)
16             cin >> maze[i][j];
17     CL(used, 0);
18     CL(chessboard, 0);
19     DFS(0, 0, 0);
20     return 0;
21 }
22 void DFS(int x, int y, int z)//z表示所走的步数
23 {
24     used[x][y] = 1;
25     chessboard[z] = x * 10 + y;//此处用于记录新的坐标数, chessboard[][]的范围一定要注意
26 //    cout << chessboard[z] << " " << z << endl;
27     if(x==MAX-1 && y==MAX-1)
28     {
29         for(i = 0; i <= z; i++)
30             printf("(%d, %d)
",chessboard[i]/10,chessboard[i]%10);
31         return ;
32     }
33     for(i = 0; i < 4; i++)
34     {
35         int xx = x + Move[i][0];
36         int yy = y + Move[i][1];
37         if(maze[xx][yy]!=1 && xx>=0 && xx<MAX && yy>=0 && yy<MAX && !used[xx][yy])//此处a,b反过来,b:代表字母,a:代表数字
38         {
39             used[xx][yy] = 1;
40             DFS(xx,yy,z+1);
41             used[xx][yy] = 0;
42         }
43     }
44     return ;
45 }
View Code

曾经多么厉害的迷宫问题,当我在这段期间的ACM刷题中,我找不到任何当初畏惧的感觉。。。。

原来人是会变的,现在我都不想停下来

原文地址:https://www.cnblogs.com/ghostTao/p/4328300.html