# Include
# Include
Using namespace std; struct point {int x; int y ;}; stack
Sta; int map [8] [8]; int moved [8] [2] = {-,-, 2,-,-2, -1,-2,-2,-1}; void dfs (int x, int y) {int visited [8] [8]; memset (visited, 0, sizeof (visited); // 0 indicates that no point * p = new point has been accessed; p-> x = x; p-> y = y; point * temp; point * q; int count = 0; sta. push (p); visited [x] [y] = 1; int a, B; count ++; while (! Sta. empty () {q = sta. top (); if (count = 16) // break cannot be found in 64; int flag = 0; for (int I = 0; I <8; I ++) {a = q-> x + moved [I] [0]; B = q-> y + moved [I] [1]; if (a> = 0 & a <4 & B> 0 & B <4 &&(! Visited [a] [B]) {temp = new point; temp-> x = a; temp-> y = B; visited [a] [B] = 1; sta. push (temp); count ++; flag = 1; // indicates that the current process can continue without backtracking. // It is not bfs, so you need to jump out of break ;}} if (flag = 0) {// you cannot continue. You need to backtrack count --; // sta. pop (); // The memory may leak. temp = sta. top (); a = temp-> x; B = temp-> y; visited [a] [B] = 0; sta. pop (); delete temp ;}} int n = sta. size (); cout <
X; B = temp-> y; cout <> x> y; dfs (x, y); return 0 ;}
The matted chessboard algorithm is not tested because the time complexity is too high. It should be correct.