fzu 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
Sample Input
Sample Output
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(状态压缩)的更多相关文章
- ACM: FZU 2107 Hua Rong Dao - DFS - 暴力
FZU 2107 Hua Rong Dao Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I6 ...
- FZU 2107 Hua Rong Dao(dfs)
Problem 2107 Hua Rong Dao Accept: 318 Submit: 703 Time Limit: 1000 mSec Memory Limit : 32768 KB Prob ...
- FZU 2107 Hua Rong Dao(暴力回溯)
dfs暴力回溯,这个代码是我修改以后的,里面的go相当简洁,以前的暴力手打太麻烦,我也来点技术含量.. #include<iostream> #include<cstring> ...
- foj Problem 2107 Hua Rong Dao
Problem 2107 Hua Rong Dao Accept: 503 Submit: 1054Time Limit: 1000 mSec Memory Limit : 32768 K ...
- FZOJ Problem 2107 Hua Rong Dao
...
- 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 ...
- POJ 3254. Corn Fields 状态压缩DP (入门级)
Corn Fields Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9806 Accepted: 5185 Descr ...
- HDU 3605:Escape(最大流+状态压缩)
http://acm.hdu.edu.cn/showproblem.php?pid=3605 题意:有n个人要去到m个星球上,这n个人每个人对m个星球有一个选择,即愿不愿意去,"Y" ...
- [HDU 4336] Card Collector (状态压缩概率dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题目大意:有n种卡片,需要吃零食收集,打开零食,出现第i种卡片的概率是p[i],也有可能不出现卡 ...
随机推荐
- PHP类与面向对象(二)
构造函数和析构函数 构造函数PHP 5 允行开发者在一个类中定义一个方法作为构造函数.具有构造函数的类会在每次创建新对象时先调用此方法,所以非常适合在使用对象之前做一些初始化工作.如果子类中定义了构造 ...
- ArcGIS Server新建主题图服务的步骤
ArcGIS Server新建主题图服务的步骤: 1.修改数据库模型图(PowerDesigner) 2.修改lygis.gdb文件数据库(发布时可以快速把表结构从gdb数据库拷贝到客户服务器的SDE ...
- php类自动装载、链式操作、魔术方法
1.自动装载实例 目录下有3个文件:index.php load.php tests文件夹 tests文件夹里有 test1.php <?php namespace Tests; class T ...
- React学习资料
以下是我整理的React学习资料,包括:React基础.Redux.reat-router, redux middleware, higher order components, React验证等, ...
- windows 2012 试用180天
windows server 2012 官方下载,可以使用180天, 快到期的时候执行以下命令 slmgr.vbs -rearm
- liunx 套接字编程(Linux_C++)
网络中的进程是如何通信的? 在网络中进程之间进行通信的时候,那么每个通信的进程必须知道它要和哪个计算机上的哪个进程通信.否则通信无从谈起!在本地可以通过进程PID来唯一标识一个进程,但是在网络中这是行 ...
- 推荐算法——距离算法
本文内容 用户评分表 曼哈顿(Manhattan)距离 欧式(Euclidean)距离 余弦相似度(cos simliarity) 推荐算法以及数据挖掘算法,计算"距离"是必须的~ ...
- 微信公众平台开发视频教程-03-获取Access Token和获取微信服务器IP,添加微信菜单
1 获取access token 此token是以后每次调用微信接口都会带上的票据,token是公众号全局唯一票据,在调用其他接口之前都需要先得到token,taoken长度至少512个字符,通常用s ...
- Javascript sleep 函数
此函数仅适合在10秒内 sleep(5) 超过10秒CPU 会吃不消 <script type="text/javascript"> function sleep(se ...
- Faster R-CNN CPU环境搭建
操作系统: bigtop@bigtop-SdcOS-Hypervisor:~/py-faster-rcnn/tools$ cat /etc/issue Ubuntu LTS \n \l Python版 ...