#include using namespace std; const int n=4; int A[4][4]; bool vis[4][4]; const int dy[]={0, 1, 0,-1}; const int dx[]={1, 0,-1, 0}; bool dfs(int i, int j){ if(vis[i][j]) return false; vis[i][j]=true; bool ok=true; for(int k=0;k=n || xx<0 || xx>=n) continue; swap(A[i][j], A[yy][xx]); if(dfs(yy, xx)) return true; swap(A[i][j], A[yy][xx]); } vis[i][j]=false; return false; } int main(){ while(1){ for(int i=0;i> A[i][j])) return 0; } memset(vis,0,sizeof(vis)); for(int i=0;i