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. V4L2编程 视频采集-范例

    http://linuxtv.org/downloads/legacy/video4linux/API/V4L2_API/v4l2spec/: http://blog.csdn.net/kangear ...

  2. php十行代码将xml转成数组

    <?php header("Content-Type:text/html;charset=utf-8"); function xml2array($filename){ $x ...

  3. jQuery中 wrap() wrapAll() 与 wrapInner()的差异

    wrap() 方法把每个被选元素放置在指定的 HTML 内容或元素中.jQuery 文档操作 - wrapAll() 方法 wrapAll() 在指定的 HTML 内容或元素中放置所有被选的元素.jQ ...

  4. 阿里云ACE下的PHP开发环境搭建

    阿里云ACE下的PHP开发环境搭建 本系列文章由ex_net(张建波)编写.转载请注明出处. http://blog.csdn.net/ex_net/article/details/23999053 ...

  5. jquery 中的回调函数,回调函数(callback)是什么?

    知乎上果然大牛比较多 大神解释如下: 你到一个商店买东西,刚好你要的东西没有货,于是你在店员那里留下了你的电话,过了几天店里有货了,店员就打了你的电话,然后你接到电话后就到店里去取了货.在这个例子里, ...

  6. C#资源释放及Dispose、Close和析构方法

    https://www.cnblogs.com/luminji/archive/2011/01/05/1926468.html C#资源释放及Dispose.Close和析构方法   备注:此文的部分 ...

  7. cocos2d-x 2.2 创建项目

    楼主用的是2.2版本号 曾经的版本号是要在vs中加入模版 建立项目 但新版本号更新后使用python建立项目 最好是python2.7以上 找到create_project.py文件所在路径  too ...

  8. Maven------电脑安装Maven

    转载: http://blog.csdn.net/jiuqiyuliang/article/details/45390313 注意:修改本地仓库路径时,<localRepository>D ...

  9. 超全面的JavaWeb笔记day18<事务&连接池&DBUtils>

    1.事务 ACID 原子性 一致性 隔离性 持久性 mysql中开启和关闭事务 开启事务:START TRANSACTION 结束事务 提交事务:COMMIT 回滚事务:ROLLBACK JDBC中开 ...

  10. 超全面的JavaWeb笔记day14<用户注册登录>

    案例:用户注册登录 要求:3层框架,使用验证码 1 功能分析 l 注册 l 登录 1.1 JSP页面 l regist.jsp Ø 注册表单:用户输入注册信息: Ø 回显错误信息:当注册失败时,显示错 ...