FZU 2107 Hua Rong Dao

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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

Hint

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

 
/*/
题意:
华容道,N*4的格子,N=[1,4],一个曹操 2*2 有 2*1、1*2和1*1的士兵,问有多少中放法。 一开始不知道自己怎么想的,看一下数据这么小,而且1,2,3很容易就推出来了,以为可以推出来,【MDZZ】结果在N==4这种情况下爆炸了。。 下面进入正题。直接DFS暴力。 如果怕超时可以打表,实际上不会。 AC代码:
/*/
#include"algorithm"
#include"iostream"
#include"cstring"
#include"cstdlib"
#include"cstdio"
#include"string"
#include"vector"
#include"stack"
#include"queue"
#include"cmath"
#include"map"
using namespace std;
typedef long long LL ;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define FK(x) cout<<"["<<x<<"]\n"
#define memset(x,y) memset(x,y,sizeof(x))
#define memcpy(x,y) memcpy(x,y,sizeof(x))
#define bigfor(T) for(int qq=1;qq<= T ;qq++)
int n;
int ans,flag;
bool vis[10][10]; bool check(int x,int y) {
if(x<0||y<0||x>=n||y>=4||vis[x][y])return 0;
return 1;
} void DFS(int x) {
if(x==4*n&&flag==1) {
ans++;
return ;
}
if(x>=4*n) {
return ;
}
for(int i=0; i<4; i++) {
for(int j=0; j<4; j++) {
if(check(i,j)&&check(i+1,j)&&check(i,j+1)&&check(i+1,j+1)&&!flag) {
vis[i][j]=vis[i+1][j]=vis[i][j+1]=vis[i+1][j+1]=1;
flag=1;
DFS(x+4);
vis[i][j]=vis[i+1][j]=vis[i][j+1]=vis[i+1][j+1]=0;
flag=0;
}
if(check(i,j)&&check(i+1,j)) {
vis[i][j]=vis[i+1][j]=1;
DFS(x+2);
vis[i][j]=vis[i+1][j]=0;
}
if(check(i,j)&&check(i,j+1)) {
vis[i][j]=vis[i][j+1]=1;
DFS(x+2);
vis[i][j]=vis[i][j+1]=0;
}
if(check(i,j)) {
vis[i][j]=1;
DFS(x+1);
vis[i][j]=0;
return ;
}
}
}
}
//int _ans[5]={0,0,18,284,4862};
int main() {
int T;S
scanf("%d",&T);
bigfor(T) {
scanf("%d",&n);
memset(vis,0);
flag=0;
ans=0;
DFS(0);
printf("%d\n",ans);
}
return 0;
}

  

 

ACM: FZU 2107 Hua Rong Dao - DFS - 暴力的更多相关文章

  1. FZU 2107 Hua Rong Dao(dfs)

    Problem 2107 Hua Rong Dao Accept: 318 Submit: 703 Time Limit: 1000 mSec Memory Limit : 32768 KB Prob ...

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

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

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

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

  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. ACM: Gym 100935G Board Game - DFS暴力搜索

    Board Game Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u  Gym 100 ...

  8. hdu 5612 Baby Ming and Matrix games(dfs暴力)

    Problem Description These few days, Baby Ming is addicted to playing a matrix game. Given a n∗m matr ...

  9. hdu 1010 Tempter of the Bone(dfs暴力)

    Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...

随机推荐

  1. CentOS添加163源

    1.备份/etc/yum.repos.d/CentOS-Base.repo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-B ...

  2. XMPP作为一个工具的意义

    学习XMPP就是拥有位当前应用程序添加实时,推送,社交功能所需的工具.虽然浏览器不支持XMPP通讯,但是我们可以通过BOSH技术解决. 一个XMPP网络包含如下 服务器:为XMPP节提供路由,是否支持 ...

  3. vijos1250 最勇敢的机器人

    背景 Wind设计了很多机器人.但是它们都认为自己是最强的,于是,一场比赛开始了~ 描述 机器人们都想知道谁是最勇敢的,于是它们比赛搬运一些物品. 它们到了一个仓库,里面有n个物品,每个物品都有一个价 ...

  4. 清北学堂模拟赛day7 错排问题

    /* 考虑一下已经放回m本书的情况,已经有书的格子不要管他,考虑没有书的格子,不考虑错排有(n-m)!种,在逐步考虑有放回原来位置的情况,已经放出去和已经被占好的格子,不用考虑,剩下全都考虑,设t=x ...

  5. [Data Structure & Algorithm] 八大排序算法

    排序有内部排序和外部排序之分,内部排序是数据记录在内存中进行排序,而外部排序是因排序的数据很大,一次不能容纳全部的排序记录,在排序过程中需要访问外存.我们这里说的八大排序算法均为内部排序. 下图为排序 ...

  6. 【荐】使用eval()、new Function()将JSON字符串转换为JSON对象

    在JS中将JSON的字符串解析成JSON数据格式,一般有两种方式: 1.一种为使用eval()函数. 2. 使用Function对象来进行返回解析. 第一种解析方式:使用eval函数来解析,并且使用j ...

  7. ecshop编辑器FCKeditor修改成KindEditor编辑批量上传图片

    ecshop一直使用的编辑器是fck,这个不用多说,相信很多朋友用的很悲剧吧,特别是图片不能批量上传图片.     今天小编就分享一下怎么换掉fck,放上实用的kindeditor,最新ecshop版 ...

  8. 构建高可用ZooKeeper集群(转载)

    ZooKeeper 是 Apache 的一个顶级项目,为分布式应用提供高效.高可用的分布式协调服务,提供了诸如数据发布/订阅.负载均衡.命名服务.分布式协调/通知和分布式锁等分布式基础服务.由于 Zo ...

  9. python 小试题

    有个同事要帮一个朋友做一个小试题,题目如图: 由于个人在学习python路上,所以想用python 写出来这道题,来练练手,苦思冥想,再加上受同事的一些启发,加以扩展,写出代码如下: #!/usr/b ...

  10. Ubuntu 16.04 64位 搭建 node.js NodeJS 环境

    我的系统环境: Ubuntu 16.04 64位 本文内容亲测可用, 请放心食用 使用淘宝镜像 淘宝镜像官网是https://npm.taobao.org/ 使用淘宝镜像前请自行安装好 npm 和 n ...