Cao Cao was hunted down by thousands of enemy soldiers when he escaped from Hua Rong Dao. Assuming Hua Rong Dao is a narrow aisle (one N*4 rectangle), while Cao Cao can be regarded as one 2*2 grid. Cross general can be regarded as one 1*2 grid.Vertical general can be regarded as one 2*1 grid. Soldiers can be regarded as one 1*1 grid. Now Hua Rong Dao is full of people, no grid is empty.
There is only one Cao Cao. The number of Cross general, vertical general, and soldier is not fixed. How many ways can all the people stand?
Input
There is a single integer T (T≤4) in the first line of the test data indicating that there are T test cases.
Then for each case, only one integer N (1≤N≤4) in a single line indicates the length of Hua Rong Dao.
2 1 2Sample Output
0 18
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=10;
int mp[maxn][maxn];
int vis[maxn][maxn];
/*
有的时候,感觉做事情总是有点遗憾,不像是mmc,人家做任何事情
都是很仔细,可是自己做事情,总是能减则减,不想着把事情做到自己的极致,
这就很致命,不是那种追求完美,我们也就会凋亡
这个递归也是蛮有意思的,第一个点我一开始是错误的思维,我应该考虑的是每一个点,能不能放,
而不是每一行,能不能放,如果每一行的话,就会导致我们一开始的中间会填不满,导致错误
还有就是 这种没有可以进入点的话,就会导致没有办法判断,导致漏掉一些个情况
*/
int n=2;
int ans=0;
void print(int n,int y){
printf("******\n");
for(int i=1;i<=n;i++){
for(int j=1;j<=y;j++){
printf(" %d",vis[i][j]);
}
printf("\n");
}
}
void dfs(int ox,int oy){
if(oy>4){
oy=1,ox++;
}
if(ox>n){
ans++;
return;
}
int flag=0;
for(int i=oy;i<=4;i++){
if(!vis[ox][i]){
flag=1;
if(i<4&&!vis[ox][i+1]){
vis[ox][i]=vis[ox][i+1]=2;
dfs(ox,i+2);
vis[ox][i]=vis[ox][i+1]=0;
}
if(ox<n&&!vis[ox+1][i]){
vis[ox][i]=vis[ox+1][i]=3;
dfs(ox,i+1);
vis[ox][i]=vis[ox+1][i]=0;
}
vis[ox][i]=4;
dfs(ox,i+1);
vis[ox][i]=0;
break;
}
}
if(!flag) dfs(ox+1,1);
/*
如果不加上这句话的话,
1 1 3 3
2 2 3 3
导致到了第二行,没有办法进入第三行,导致没有办法检测,就会丢掉一些情况
*/
}
void vis_caocao(int x,int y){
memset(vis,0,sizeof(vis));
for(int i=x;i<x+2;i++){
for(int j=y;j<y+2;j++){
vis[i][j]=1;
}
}
}
int main(){
//freopen("123.txt","w",stdout);
for(int i=1;i<n;i++){
for(int j=1;j<4;j++){
vis_caocao(i,j);
dfs(1,1);
printf("ans:%d\n",ans);
}
}
printf("%d\n",ans);
return 0;
}
#include<cstring>
#include<cstdio>
using namespace std;
int ans[10]={0,0,18,284,4862};
int main(){
//123
int T;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
printf("%d\n",ans[n]);
}
return 0;
}