#include<bits/stdc++.h> using namespace std; int n,d=1; char a[24][24]; int fx[4]={0,-1,0,1}; int fy[4]={1,0,-1,0}; int b[24][24]; int c[24][3]; void dfs(int x,int y,int k){ b[1][1]=1; c[1][1]=1; c[1][2]=1; a[x][y]='1'; if(x==n&&y==n){ for(int i=1;i<=d;i++){ for(int j=1;j<=1;j++){ cout<<"("<<c[i][j]<<","<<c[i][j+1]<<")"; if(i==d&&j==1)cout<<""; else cout<<"->"; } } // for(int i=1;i<=n;i++){ // for(int j=1;j<=n;j++){ // cout<<a[i][j]; // } // cout<<endl; // } exit(0); } int l=0; for(int i=0;i<=3;i++){ int tx=x+fx[i]; int ty=y+fy[i]; if(tx>=1&&tx<=n&&ty>=1&&ty<=n&&a[tx][ty]=='0'){ b[tx][ty]=k; d++; c[d][1]=tx; c[d][2]=ty; dfs(tx,ty,k+1); } else { l++; } if(l==4){ for(int h=1;h<=d;h++){ for(int j=1;j<=2;j++){ c[h][j]=0; } } d=1; for(int h=1;h<=n;h++){ for(int j=1;j<=n;j++){ b[h][j]=0; } } } } } int main(){ cin>>n; for(int i=1;i<=n;i++){ for(int j=1;j<=n;j++){ cin>>a[i][j]; } } dfs(1,1,1);//从1,1开始 return 0; } /************************************************************** Problem: 1431 User: chenjingqi Language: C++ Result: Wrong Answer ****************************************************************/