本文最后更新于 1830 天前,其中的信息可能已经有所发展或是发生改变。
#include<iostream>
#include<cstring>
using namespace std;
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
int arr[7][7];
void dfs(int start,int x,int y){
if(y==6&&x==(6-start)){
for(int i=0;i<7;i++){
for(int j=0;j<7;j++){
cout<<arr[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
//judge();
return;
}
for(int i=0;i<4;i++){
int tempx=x+dx[i];
int tempy=y+dy[i];
if(tempx>=0&&tempx<7&&tempy>=0&&tempy<7&&arr[tempx][tempy]==0){
arr[tempx][tempy]=1;
for(int i=0;i<7;i++){
for(int j=0;j<7;j++){
cout<<arr[i][j]<<" ";
}
cout<<endl;
}
cout<<endl;
dfs(start,tempx,tempy);
arr[tempx][tempy]=0;
}
}
}
int main(){
memset(arr,0,sizeof(arr));
for(int i=0;i<4;i++){
dfs(i,0,0);
arr[0][0]=1;
}
return 0;
}