题解:从中心出发,减到边就算一种,两个方向反向减,关于两点的 位置中心对称
AC代码如下:
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int book[8][8],nex1[4][2]={0,1,1,0,0,-1,-1,0},nex2[4][2]={0,-1,-1,0,0,1,1,0},cnt;
bool judge(int x,int y)
{
if(x<=0||x>=6||y<=0||y>=6)
return true;
return false;
}
void dfs(int x,int y,int nx,int ny)
{
if(judge(x,y))
{
cnt++;
return ;
}
int i,xiax,xiay,a,b;
for(i=0;i<4;i++)
{
xiax=x+nex1[i][0];
xiay=y+nex1[i][1];
a=nx+nex2[i][0];
b=ny+nex2[i][1];
if(book[xiax][xiay]==0 && book[a][b]==0)
{
book[xiax][xiay]=1;
book[a][b]=1;
dfs(xiax,xiay,a,b);
book[xiax][xiay]=0;
book[a][b]=0;
}
}
return ;
}
int main()
{
memset(book,0,sizeof(book));
cnt=0;
book[3][3]=1;
dfs(3,3,3,3);
cout<<cnt/4<<endl;
}
answer:509