题目描述
DD wants to send a gift to his best friend CC as her birthday is coming. However, he can’t afford expensive gifts, and he is so lazy that he is not willing to do complex things. So he decides to prepare a paper cut for CC’s birthday gift, which symbolizes their great friendship~~
DD has a square colored paper which consists of n*n small squares. Due to his tastes, he wants to cut the paper into two identical pieces. DD also wants to cut as many different figures as he can but each sheet can be only cut once, so he asks you how many sheets does he need to prepare at most.
for example:
输入描述:
Input contains multiple test cases. The first line contains an integer T (1<=T<=20), which is the number of test cases.Then the first line of each test case contains an integer n (1<=n<10).
输出描述:
The answer;
示例1
输入
1 4
输出
11
point:
从中心开始DFS。
#include <set>
#include <map>
#include <math.h>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define LL long long
const LL maxn = 55;
int dir[4][2]={0,1,0,-1,1,0,-1,0};
int n;
int ans;
int flag[maxn][maxn];
int check(int x,int y)
{
if(x==1||x==n+1||y==1||y==n+1) return 1;
return 0;
}
int out(int x,int y)
{
if(x >= 1 && x <= n+1 && y >= 1 && y <= n+1) return 0;
return 1;
}
void dfs(int x1,int y1,int x2,int y2)
{
if(check(x1,y1)&&check(x2,y2)){
ans++;
return;
}
for(int i=0;i<4;i++){
int xx1=x1+dir[i][0];
int yy1=y1+dir[i][1];
int xx2=x2-dir[i][0];
int yy2=y2-dir[i][1];
if(flag[xx1][yy1]||flag[xx2][yy2]) continue;
if(out(xx1,yy1)||out(xx2,yy2)) continue;
flag[xx1][yy1]=1;
flag[xx2][yy2]=1;
dfs(xx1,yy1,xx2,yy2);
flag[xx1][yy1]=0;
flag[xx2][yy2]=0;
}
}
int main()
{
int T;
scanf("%d",&T);
while(T--){
ans = 0;
scanf("%d",&n);
memset(flag,0,sizeof flag);
if(n&1){
printf("0\n");
}else{
flag[n/2+1][n/2+1]=1;
dfs(n/2+1,n/2+1,n/2+1,n/2+1);
printf("%d\n",ans/4);
}
}
}