经典的骑士巡游问题,注意字典序最小,应该从上到下,从左到右遍历
#include#include #include using namespace std;const int maxn=30;int di[]={-1,1,-2,2,-2,2,-1,1},dj[]={-2,-2,-1,-1,1,1,2,2},n,m;bool vis[maxn][maxn];vector stak;bool backtraking(int ci,int cj,int cnt){ vis[ci][cj]=1; if(cnt==0){ for (int i=0;i =0&&ni =0&&nj =m)printf("impossible\n"); printf("\n"); } return 0;}