参考文章
![]()
1 #include<bits/stdc++.h>
2 using namespace std;
3
4 int X[] = {0, -1, 1, 0, 0};
5 int Y[] = {0, 0, 0, -1, 1};
6
7 bool vis[10][10];
8 int res = 0;
9
10 void dfs(int x, int y){
11 if(x == 0 || y == 0 || x == 6 || y == 6){
12 res++;
13 return ;
14 }
15 for(int i = 1 ; i <= 4 ; i++){ //上下左右四个方向
16 x += X[i]; y += Y[i]; //走一步
17 if(!vis[x][y]){ // 若该点未访问则继续深搜
18 vis[x][y] = true; // 当前的点标注为已访问
19 vis[6 - x][6 - y] = true;
20 dfs(x, y); // 继续深搜
21 //由于存在回溯,所以要把状态恢复
22 vis[6 - x][6 - y] = false;
23 vis[x][y] = false;
24 }
25 x -= X[i]; y -= Y[i];
26 }
27 }
28
29 int main(){
30 vis[3][3] = true;
31 dfs(3, 3);
32 cout << res / 4 << endl;
33 return 0;
34 }