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],也有可能不出现卡 ...
随机推荐
- Leetcode-122 Best Time to Buy and Sell Stock II
#122 Best Time to Buy and Sell Stock II Say you have an array for which the ith element is the pric ...
- JQ属性和css部分测试
1.attr(name|properties|key,value|fn) 设置或返回被选元素的属性值. <div class="attr">设置或返回被选元素的属性值 ...
- Python 3 数值计算
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32Type & ...
- Cocos2dx.3x入门三部曲-Hello Game项目创建(二)
一.前提: 完成cocos2d-x-3.x开发环境的安装配置. 具体参考:Cocos2d-x.3x_软件配置篇 二.本篇目标: l 创建一个名为hello game的cocos2dx 3.3的项目 ...
- mysql查看被锁住的表,正在进行的进程,已经杀掉进程的方法
mysql查看被锁的进程 //查看所有进程show processlist; //查询是否锁表show OPEN TABLES where In_use > 0; //查看被锁住的 SELECT ...
- Oracle中的索引详解
Oracle中的索引概述 索引与表一样,也属于段(segment)的一种.里面存放了用户的数据,跟表一样需要占用磁盘空间.索引是一种允许直接访问数据表中某一数据行的树型结构,为了提高查询效率而引入,是 ...
- Scala access modifiers and qualifiers in detail
来自:http://www.jesperdj.com/2016/01/08/scala-access-modifiers-and-qualifiers-in-detail/ Just like Jav ...
- GridView第一个Item中的CheckBox不工作
问题:如题 解决办法: 修改后: ViewGroup.LayoutParams params =helper.getConvertView().getLayoutParams(); params.wi ...
- redmine v3.02版的安装问题
redmine v3.0.2版的安装问题 参考上次在朋友公司的云主机上安装的过程: 1. 下载 2. gem install bundler 3. bundle install 出现 rmagick ...
- Conway's Game of Life: An Exercise in WPF, MVVM and C#
This blog post was written for the Lockheed Martin Insight blog, sharing here for the external audie ...