Problem 2107 Hua Rong Dao

Accept: 318 Submit: 703

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

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

Sample Input

2

1

2

Sample Output

0

18

暴力搜索

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
#include <stdio.h> using namespace std;
int vis[10][10];
int n;
int ans;
bool flag;
int judge(int x,int y)
{
if(x<1||x>n||y<1||y>4||vis[x][y])
return 0;
return 1;
}
void dfs(int count)
{
if(count==n*4&&flag)
{
ans++;
return;
}
if(count>=n*4)
return;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=4;j++)
{
if(judge(i,j)&&judge(i+1,j+1)&&judge(i,j+1)&&judge(i+1,j)&&!flag)
{
flag=1;
vis[i][j]=1;vis[i+1][j+1]=1;vis[i][j+1]=1;vis[i+1][j]=1;
dfs(count+4);
flag=0;
vis[i][j]=0;vis[i+1][j+1]=0;vis[i][j+1]=0;vis[i+1][j]=0;
}
if(judge(i,j)&&judge(i,j+1))
{
vis[i][j]=1;vis[i][j+1]=1;
dfs(count+2);
vis[i][j]=0;vis[i][j+1]=0;
}
if(judge(i,j)&&judge(i+1,j))
{
vis[i][j]=1;vis[i+1][j]=1;
dfs(count+2);
vis[i][j]=0;vis[i+1][j]=0;
}
if(judge(i,j))
{
vis[i][j]=1;
dfs(count+1);
vis[i][j]=0;
return; } }
}
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
memset(vis,0,sizeof(vis));
ans=0;
flag=0;
dfs(0);
printf("%d\n",ans);
}
return 0; }

最新文章

  1. 如何快速清除ZBrush画布中多余图像
  2. Android使用ListView应该注意的地方
  3. PHP的学习--使用PhpDocumentor 2生成API文档
  4. dexDebug ExecException finished with non-zero exit value 2
  5. div均匀分布代码实例
  6. HDU 5744 Keep On Movin (贪心)
  7. 监控CPU和内存的使用
  8. 使用java求高精度除法,要求保留N位小数
  9. Java之泛型编程
  10. 21. pt-stalk
  11. log4net 单独项目
  12. CIKM 18 | 蚂蚁金服论文:基于异构图神经网络的恶意账户识别方法
  13. day11- python生成式和生成器
  14. 关联本地文件夹到 GitLab 项目
  15. session超时时间设置
  16. DNA甲基化研究概述
  17. linux-shell-screen后台调用-后台运行脚本和命令-仿start命令-伪窗口界面
  18. 【刷题】BZOJ 4650 [Noi2016]优秀的拆分
  19. selenium使用中遇到的问题
  20. Orders

热门文章

  1. AngularJS开发经验
  2. PNG透明兼容IE6的几种方法(转)
  3. Java处理图片时编译不通过
  4. HTC Desire 816 root教程和方法
  5. 比較JS合并数组的各种方法及其优劣
  6. date详解
  7. Spark-Hadoop、Hive、Spark 之间是什么关系?(转)
  8. Eclipse的调试功能的10个小窍门
  9. RabbitMQ消息确认(发送确认,接收确认)
  10. [转]ASP.NET MVC 5 - 验证编辑方法(Edit method)和编辑视图(Edit view)