Problem 2107 Hua Rong Dao

Accept: 106    Submit: 197
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

212

 Sample Output

018

 Hint

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

 Source

“高教社杯”第三届福建省大学生程序设计竞赛

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int N=(1<<4);
int f[6][N][2]={0};//f[i][j][k]//放完第i-1行第i行的状态j,k=1放曹操
void dfs(int row,int col,int pre,int now,int cao,int k){
if(col>=4){//放完4列,pre={1111}
f[row][now][cao]+=k;//放完pre得到f[now]+=f[pre]
//cout<<row<<" "<<now<<" "<<cao<<endl;
return;
}
if(pre&(1<<col)){//第col已经放过
dfs(row,col+1,pre,now,cao,k);
return;
}
//a grid
dfs(row,col+1,pre|(1<<col),now,cao,k);
//a 1*2
dfs(row,col+1,pre|(1<<col),now|(1<<col),cao,k);//放一竖,多出一块
int t=(1<<col)|(1<<(col+1));
if(col<3&&(pre&(1<<(col+1)))==0){
//a 2*1
dfs(row,col+1,pre|t,now,cao,k);
//put caocao
if(cao==0)dfs(row,col+1,pre|t,now|t,1,k);
}
}
int main(){
int i,j,k;
f[0][N-1][0]=1;
for(i=1;i<=5;i++)
for(j=0;j<N;j++){
if(f[i-1][j][0])dfs(i,0,j,0,0,f[i-1][j][0]);
if(f[i-1][j][1])dfs(i,0,j,0,1,f[i-1][j][1]);
}
scanf("%d",&k);
while(k--){
scanf("%d",&i);
printf("%d\n",f[i+1][0][1]);
}
return 0;
}

fzu 2107 Hua Rong Dao(状态压缩)的更多相关文章

  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(dfs)

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

  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. FZU 2060 The Sum of Sub-matrices(状态压缩DP)

    The Sum of Sub-matrices Description Seen draw a big 3*n matrix , whose entries Ai,j are all integer ...

  7. POJ 3254. Corn Fields 状态压缩DP (入门级)

    Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Descr ...

  8. HDU 3605:Escape(最大流+状态压缩)

    http://acm.hdu.edu.cn/showproblem.php?pid=3605 题意:有n个人要去到m个星球上,这n个人每个人对m个星球有一个选择,即愿不愿意去,"Y" ...

  9. [HDU 4336] Card Collector (状态压缩概率dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题目大意:有n种卡片,需要吃零食收集,打开零食,出现第i种卡片的概率是p[i],也有可能不出现卡 ...

随机推荐

  1. Maven之打包时配置文件替换

    在JavaWeb项目中,使用maven打包.在打正式包时,需要手动修改数据库配置为线上环境的地址,这样每次修改起来比较麻烦. 搜索了一些资料后,大部分的做法或原理都是预先使用表达式占位符,然后在打包时 ...

  2. MF-800U

    MF-800U 价格:200元左右 https://item.taobao.com/item.htm?spm=a230r.1.14.6.kfkqoY&id=4963072384&ns= ...

  3. android: UriMatcher的用法

    ContentProvider是Android四大组件之一,网上也有不少关于它的文章,基本用法都可以查到,但关于UriMatcher在其中的作用,文章中都有例子,但我觉得还没有说清楚. 先说为什么用U ...

  4. VS2013中Python学习笔记[Django Web的第一个网页]

    前言 前面我简单介绍了Python的Hello World.看到有人问我搞搞Python的Web,一时兴起,就来试试看. 第一篇 VS2013中Python学习笔记[环境搭建] 简单介绍Python环 ...

  5. ORACLE 监听日志文件太大停止写监听日志引起数据库连接不上问题

    生产库监听日志文件太大(达到4G多),发现oracle停止写监听日志,检查参数log_file,log_directory,log_status 均正常,数据库运行也正常. 经确认确实为监听日志过大引 ...

  6. LM-Sensors unable to load driver module

    Fix - sort of - for LM-Sensors unable to load driver module In short: In /etc/default/grub set GRUB_ ...

  7. iOS RSA 证书加密

    #import "GLQyRsa.h" #import "GLSupprot.h" #import "GLLoginViewController.h& ...

  8. FoxMail的Bug

    Foxmail 7.2 build6.040,win7中文专业版 下载腾讯的企业邮箱的邮件, 自动配置为imap收邮件 收件箱应该为1740封 邮件 实际foxmail却只收到1500多封 改成pop ...

  9. MySQL模拟:线上误update的恢复

    作为DBA,细心.沉稳是首要的基本素质.不过总有那么一会心烦意乱或者开发同学出现误操作之类的...这里模拟一个误update操作,然后恢复. 如果开发同学有误操作之后最好先别乱动生产环境,需要记录几个 ...

  10. js中“==”与"==="的区别

    首先,== equality 等同,=== identity 恒等. ==, 两边值类型不同的时候,要先进行类型转换,再比较. ===,不做类型转换,类型不同的一定不等. 一言以蔽之:==先转换类型再 ...