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; }

FZU 2107 Hua Rong Dao(dfs)的更多相关文章

  1. ACM: FZU 2107 Hua Rong Dao - DFS - 暴力

    FZU 2107 Hua Rong Dao Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I6 ...

  2. fzu 2107 Hua Rong Dao(状态压缩)

    Problem 2107 Hua Rong Dao Accept: 106    Submit: 197 Time Limit: 1000 mSec    Memory Limit : 32768 K ...

  3. FZU 2107 Hua Rong Dao(暴力回溯)

    dfs暴力回溯,这个代码是我修改以后的,里面的go相当简洁,以前的暴力手打太麻烦,我也来点技术含量.. #include<iostream> #include<cstring> ...

  4. foj Problem 2107 Hua Rong Dao

    Problem 2107 Hua Rong Dao Accept: 503    Submit: 1054Time Limit: 1000 mSec    Memory Limit : 32768 K ...

  5. FZOJ Problem 2107 Hua Rong Dao

                                                                                                        ...

  6. ACM: FZU 2150 Fire Game - DFS+BFS+枝剪 或者 纯BFS+枝剪

    FZU 2150 Fire Game Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  7. FZU 2176 easy problem (DFS序+树状数组)

    对于一颗树,dfs遍历为每个节点标号,在进入一个树是标号和在遍历完这个树的子树后标号,那么子树所有的标号都在这两个数之间,是一个连续的区间.(好神奇~~~) 这样每次操作一个结点的子树时,在每个点的开 ...

  8. FZU 2150 Fire Game (bfs+dfs)

    Problem Description Fat brother and Maze are playing a kind of special (hentai) game on an N*M board ...

  9. 数据结构实验之图论二:图的深度遍历(SDUT 2107)(简单DFS)

    题解:图的深度遍历就是顺着一个最初的结点开始,把与它相邻的结点都找到,也就是一直往下搜索直到尽头,然后在顺次找其他的结点. #include <bits/stdc++.h> using n ...

随机推荐

  1. Hibernate 注解中CascadeType用法汇总

    这两天,参加一个课程设计,同时这个项目又作为一个模块镶嵌到其他项目中,考虑如此,应与原先的架构相同,因牵扯到留言和相互@功能,故数据库之间OneToOne,OneToMany,ManyToMany之风 ...

  2. 教你如何架设linux邮件服务器postfix

    检查linux是否有安装postfix和dovecot 检查命令如下: Rpm  -qa |grep  postfix; Rpm –qa |grep dovecot; 如果没有显示任何数据,表明没有安 ...

  3. 学习 TList 类的实现[2]

    我原来以为 TList 可能是一个链表, 其实只是一个数组而已. 你知道它包含着多大一个数组吗? MaxListSize 个!MaxListSize 是 Delphi 在 Classes 单元定义的一 ...

  4. tiny6410的linux操作系统实验开发

    ---恢复内容开始--- 1.前期由于2440 的4.3寸屏太小.后来修改程序准备在tiny6410增强版的S70屏上用.但是前期移植再用yaffs的文件系统,但是6410是(MLC)的磁盘,根本就不 ...

  5. C# Serializable(转)

    C# Serializable System.SerializableAttribute 串行化是指存储和获取磁盘文件.内存或其他地方中的对象.在串行化时,所有的实例数据都保存到存储介质上,在取消串行 ...

  6. K - problem 问题

    Leetcode 有几个题目, 分别是 2sum, 3sum(closest), 4sum 的求和问题和 single Number I II, 这些题目难点在于用最低的时间复杂度找到结果 2-sum ...

  7. asp.net返回值当文件下载问题

    mvc中返回的javascript当做文件下载 解决方案 Response.ContentEncoding = System.Text.Encoding.UTF8;   Response.Conten ...

  8. swift -- 计步器CMPedometer的使用

    最近公司接了个项目,是一款运动类型的APP,可以检测运动量(例如:步数,上下楼等).睡眠信息.速度等信息,因为以前粗略的了解过传感器方面的相关信息,知道主要是苹果设备内置的传感器在起作用,传感器的种类 ...

  9. python2.0_s12_day11_SqlAlchemy使用介绍

    SqlAlchemy ORM ORM的解释; 简单点:对象关系映射. 需求:我们写一个主机管理,把主机信息存在数据库,一开始我们编程不熟练的时候,执行命令时候要调用数据库,会把相应的SQL语句写到代码 ...

  10. ionic跳转(一)

    在ionic中可以用两个办法写中转链接(写模版地址或路由地址) 1)a 标签的 href <a class="button button-icon icon ion-android-h ...