Accept: 401 Submit: 853
Time Limit: 1000 mSec Memory Limit : 32768
KB
Problem Description
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. Output
can stand in a single line.
Sample Input
1
2
Sample Output
18
Hint
Here are 2 possible ways for the Hua Rong Dao 2*4.
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
int N;
int vis[][];
bool flag = ;
int num ;
bool judge(int x,int y) {
if (x >= && x < N&&y >= && y < &&!vis[x][y]) {//!!!
return true;
}
return false;
} void dfs(int count) {
if (count == N * && flag) { num++; return; }
if (count >= N * )return;
for (int i = ; i < N; i++) {
for (int j = ; j < ; j++) {
if (judge(i, j) && judge(i + , j) && judge(i, j + ) && judge(i + , j + ) && !flag) {
flag = ;
vis[i][j] = vis[i + ][j] = vis[i][j + ] = vis[i + ][j + ] = ;
dfs(count + );
flag = ;
vis[i][j] = vis[i + ][j] = vis[i][j + ] = vis[i + ][j + ] = ;
}
if (judge(i, j) && judge(i + , j)) {
vis[i][j] = vis[i + ][j] = ;
dfs(count + );
vis[i][j] = vis[i + ][j] = ;
}
if (judge(i, j) && judge(i, j + )) {
vis[i][j] = vis[i][j + ] = ;
dfs(count + );
vis[i][j] = vis[i][j + ] = ;
}
if (judge(i, j)) {
vis[i][j] = ;
dfs(count + );
vis[i][j] = ;
return;//!!!!
}
}
}
} int main() {
int T;
scanf("%d",&T);
while (T--) {
scanf("%d",&N);
num =flag= ;
memset(vis,,sizeof(vis));
dfs();
printf("%d\n",num);
}
return ;
}