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. Python面试题(一)

    **晚上在公司的论坛上看到一道面试题,题目如下:随机给定一字符串和字符,要求重排,比如:'abde','c'.重排之后变成'abcde' **看到他们给的答案很多都是二分法重排,既然是字符类的处理,当 ...

  2. python实现curl功能

    之前写过一篇文章关于python CURL模块的,在这里我们从urllib来实现同样的功能.具体代码如下: import urllib import urllib2 import json #发起请求 ...

  3. raspberry pi 如何汉化显示中文

    1 树莓派初装系统之后,首次启动会出现“raspi-config”工具,如下图:(若不是初次启动,在命令模式下,请输入 sudo raspi-config 命令,即可调出此界面.若在图形桌面下,打开桌 ...

  4. 小白学数据分析----->DNU/DAU

    行业指标观察分析-DNU/DAU 写在分析之前 一直以来,我们对于数据都是在做加法,也希望这个过程中,不断搜罗和变换出来更多的数据指标,维度等等.而在实际的分析中,我们发现,一如我们给用户提供产品一样 ...

  5. 画之国 Le tableau (2011)

    在佛斯特的肚子里,靠近幽门的地方,两只阿米巴原虫快乐地生活着.他们的日子过得很舒服,从来没饿过肚子,而且根本用不着干活:因为他们就是所谓的寄生虫.这两个好朋友相处得很愉快,但时不时也会争论不休,因为他 ...

  6. Ubuntu下vsftpd配置实例,超级简单,高度可用

    看了网上很多关于vsftpd的安装配置教程,发现很多都是不可以用的,经过多次尝试,总结了一个最简单的设置方法. 第一步:安装vsftpd sudo apt-get install vsftpd 第二步 ...

  7. EF性能之关联加载

    鱼和熊掌不能兼得 ——中国谚语 一.介绍 Entity Framework作为一个优秀的ORM框架,它使得操作数据库就像操作内存中的数据一样,但是这种抽象是有性能代价的,故鱼和熊掌不能兼得.但是,通过 ...

  8. LANDR:在线母带处理

    二前年没看这报道,我就有这样的想法.最近也在完成个别功能,但还是慢,原因有二个:1) 一个人做太慢了,这个要做好有太多工作要做:2) 音乐相关知识功底太差,很多时间在学基础的乐理知识. LANDR是一 ...

  9. js 去掉字符串前面的0

    <script>var a='00123';alert(a.replace(/\b(0+)/gi,""));</script>

  10. centos7 Linux 尝试使用crontab

    一.安装crontab [root@CentOS ~]# yum install vixie-cron[root@CentOS ~]# yum install crontabs 说明:vixie-cr ...