FZU 2107 Hua Rong Dao (DFS)

  
  
  
  

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

For each test case, print the number of ways all the people can stand in a single line.

Sample Input

212

Sample Output

018

Hint

Here are 2 possible ways for the Hua Rong Dao 2*4.

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int a[5][5];
int ans[5]={0,0,18,284,4862};
int top,ty;
/*void dfs(int x,int y,int f,int cnt)
{
    if(x>top)
    {
        if(cnt==top*ty&&f) ans++;
        return ;
    }
    if(y>ty)
    {
        dfs(x+1,1,f,cnt);
        return ;
    }
    if(a[x][y])
    {
        dfs(x,y+1,f,cnt);
        return ;
    }
    if(f==0&&x<top&&y<ty)
    {
        if(a[x][y+1]||a[x+1][y]||a[x+1][y+1]) ;
        else
        {
            a[x][y]=1;
            a[x+1][y]=1;
            a[x+1][y+1]=1;
            a[x][y+1]=1;
            dfs(x,y+2,1,cnt+4);
            a[x][y]=0;
            a[x+1][y]=0;
            a[x+1][y+1]=0;
            a[x][y+1]=0;
        }
    }
    if(x<top)
    {
        if(a[x+1][y]==0)
        {
            a[x][y]=1;
            a[x+1][y]=1;
            dfs(x,y+1,f,cnt+2);
            a[x][y]=0;
            a[x+1][y]=0;
        }
    }
    if(y<ty)
    {
        if(a[x][y+1]==0)
        {
            a[x][y+1]=1;
            a[x][y]=1;
            dfs(x,y+2,f,cnt+2);
            a[x][y]=0;
            a[x][y+1]=0;
        }
    }
    a[x][y]=1;
    dfs(x,y+1,f,cnt+1);
    a[x][y]=0;
}*/
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&ty);
        cout<<ans[ty]<<endl;
    }
    return 0;
}


你可能感兴趣的:(FZU 2107 Hua Rong Dao (DFS))