#include <stdio.h>
void print(int (*map)[9])
{
int i,j;
for(i=0;i<8;i++)
{
for(j=0;j<9;j++)
printf("%2d",map[i][j]);
putchar('\n');
}
putchar('\n');
}
int check(int x,int y,int (*map)[9])
{
if(map[x][y]==0) return 1;
else return 0;
}
void visit(int x,int y,int (*map)[9])
{
if(x==1&&y==8)
{ map[1][8]=2;
print(map);
}
if(check(x,y,map)==1&&map[x][y+1]==0) {map[x][y]=2;visit(x,y+1,map);map[x][y]=0;}
if(check(x,y,map)==1&&map[x][y-1]==0) {map[x][y]=2;visit(x,y-1,map);map[x][y]=0;}
if(check(x,y,map)==1&&map[x+1][y]==0) {map[x][y]=2;visit(x+1,y,map);map[x][y]=0;}
if(check(x,y,map)==1&&map[x-1][y]==0) {map[x][y]=2;visit(x-1,y,map);map[x][y]=0;}
}
int main()
{
int map[8][9]={
{1,1,1,1,1,1,1,1,1},
{1,1,1,1,0,1,1,0,0},
{1,1,1,1,0,1,1,0,1},
{1,1,1,1,0,1,1,0,1},
{1,1,0,0,0,0,1,0,1},
{1,1,0,1,1,0,0,0,1},
{1,0,0,1,1,1,1,1,1},
{1,0,1,1,1,1,1,1,1}};
print(map);
visit(7,1,map);
}