HDU - 4804 Campus Design(状压+轮廓线dp)
Campus Design
The designers measured the open space and come to a conclusion that the open space is a rectangle with a length of n meters and a width of m meters. Then they split the open space into n x m squares. To make it more beautiful, the designer decides to cover the open space with 1 x 1 bricks and 1 x 2 bricks, according to the following rules:
1. All the bricks can be placed horizontally or vertically
2. The vertexes of the bricks should be placed on integer lattice points
3. The number of 1 x 1 bricks shouldn’t be less than C or more than D. The number of 1 x 2 bricks is unlimited.
4. Some squares have a flowerbed on it, so it should not be covered by any brick. (We use 0 to represent a square with flowerbet and 1 to represent other squares)
Now the designers want to know how many ways are there to cover the open space, meeting the above requirements.
InputThere are several test cases, please process till EOF.
Each test case starts with a line containing four integers N(1 <= N <= 100), M(1 <= M <= 10), C, D(1 <= C <= D <= 20). Then following N lines, each being a string with the length of M. The string consists of ‘0’ and ‘1’ only, where ‘0’ means the square should not be covered by any brick, and ‘1’ otherwise.OutputPlease print one line per test case. Each line should contain an integers representing the answer to the problem (mod 10 9 + 7).Sample Input
1 1 0 0
1
1 1 1 2
0
1 1 1 2
1
1 2 1 2
11
1 2 0 2
01
1 2 0 2
11
2 2 0 0
10
10
2 2 0 0
01
10
2 2 0 0
11
11
4 5 3 5
11111
11011
10101
11111
Sample Output
0
0
1
1
1
2
1
0
2
954 非常综合的一道轮廓线dp。开始给出已经存在的瓷砖位置,然后用1×1和1×2两种瓷砖铺满地面,其中1×1瓷砖又有限制。
只需在状态中加一维表示1×1瓷砖个数,然后利用状压判断当前状态能否填满当前行即可。
#include<bits/stdc++.h>
#define MAX 102
#define MOD 1000000007
typedef long long ll;
using namespace std; int n,m;
char s[MAX][];
int a[MAX];
ll dp[MAX][<<][];
struct Node{
int pre,now,c;
}node;
vector<Node> v; void dfs(int pos,int pre,int now,int c){
if(pos>m) return;
if(pos==m){
node.pre=pre;
node.now=now;
node.c=c;
v.push_back(node);
return;
}
dfs(pos+,(pre<<)|,(now<<)|,c); //横放1×2
dfs(pos+,pre<<,(now<<)|,c); //竖放1×2
dfs(pos+,(pre<<)|,now<<,c); //不放
dfs(pos+,(pre<<)|,(now<<)|,c+); //加入1×1
}
int main()
{
int t,i,j,k;
int c,d;
while(~scanf("%d%d%d%d",&n,&m,&c,&d)){
v.clear();
dfs(,,,);
for(i=;i<=n;i++){
scanf(" %s",s[i]+);
}
memset(dp,,sizeof(dp));
dp[][(<<m)-][]=;
for(i=;i<=n;i++){
for(j=;j<v.size();j++){
int f=;
for(k=;k<=m;k++){
if(v[j].now&(<<(m-k))){
if(s[i][k]==''){
f=;
break;
}
}
}
if(f==) continue;
int now=v[j].now;
for(k=;k<=m;k++){
if(s[i][k]==''){
now|=<<(m-k);
}
}
for(k=;k<=;k++){
if(k+v[j].c>) break;
dp[i][now][k+v[j].c]+=dp[i-][v[j].pre][k];
dp[i][now][k+v[j].c]%=MOD;
}
}
}
ll ans=;
for(i=c;i<=d;i++){
ans+=dp[n][(<<m)-][i];
ans%=MOD;
}
printf("%I64d\n",ans);
}
return ; }
HDU - 4804 Campus Design(状压+轮廓线dp)的更多相关文章
- HDU 4804 Campus Design
HDU 4804 思路: 轮廓线dp #include<bits/stdc++.h> using namespace std; #define fi first #define se se ...
- $POJ2411\ Mondriaan's\ Dream$ 状压+轮廓线$dp$
传送门 Sol 首先状压大概是很容易想到的 一般的做法大概就是枚举每种状态然后判断转移 但是这里其实可以轮廓线dp 也就是从上到下,从左到右地放方块 假设我们现在已经放到了$(i,j)$这个位置 那么 ...
- HDU - 4804 Campus Design 轮廓线dp
题意:一个nm的矩阵被12的骨牌和11的骨牌完全覆盖,11的骨牌只能放c-d次,矩阵中有障碍物 题解:dp[i][j][k]表示到了第i行,第j个状态,放过k个11的骨牌,当前位有障碍物时只有一种转移 ...
- hdu 3247 AC自动+状压dp+bfs处理
Resource Archiver Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 100000/100000 K (Java/Ot ...
- hdu 2825 aC自动机+状压dp
Wireless Password Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU 5765 Bonds(状压DP)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5765 [题目大意] 给出一张图,求每条边在所有边割集中出现的次数. [题解] 利用状压DP,计算不 ...
- HDU 4281 Judges' response 状压dp+多旅行商问题
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4281 Judges' response Time Limit: 2000/1000 MS (Java ...
- hdu 3681(bfs+二分+状压dp判断)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3681 思路:机器人从出发点出发要求走过所有的Y,因为点很少,所以就能想到经典的TSP问题.首先bfs预 ...
- hdu 4778 Gems Fight! 状压dp
转自wdd :http://blog.csdn.net/u010535824/article/details/38540835 题目链接:hdu 4778 状压DP 用DP[i]表示从i状态选到结束得 ...
随机推荐
- MongoDB在win7上的安装(精简版)
1.下载mongdb的zip文件,解压后会发现有bin文件夹,在同层目录下建一个data目录, 2.在data目录下建一个log和db文件夹, 3.在log文件下建一个MongoDB.log 文件 4 ...
- php总结4——数组的定义及函数、冒泡排序
4.1 数组的定义 数组:变量存储的有序序列. 索引数组:下标为数字的数组. $数组名称(下标) 下标从0开始的数字. 直接定义: $arr[0]=123; $arr[1]="chi ...
- Android数据格式化
1.文件大小格式化: Log.d(TAG, Formatter.formatFileSize(this, 100)); //100 B Log.d(TAG, Formatter.formatFileS ...
- 《高性能Javascript》 Summary(三)
第八章.编程实践 Programming Practices 经验: 避免使用 eval_r()和Function构造器避免二次评估.此外,给setTimeout()和setInterval()函数传 ...
- 4.2 《锋利的jQuery》jQuery中的动画
问题:queue()方法? tip0: jquery从1.9版本以上就不支持toggle()方法. // $("#panel h5.head").toggle(function() ...
- 升级GCC 6.2编译LLVM的问题
[ 55%] Built target RTInterception.x86_64 [ 55%] Building ASM object projects/compiler-rt/lib/saniti ...
- 图形绘制处理逻辑VC
// 逻辑1:先从资源中读取背景资源,然后将绘图对象与DC绑定,通过绘图对象绘出背景 // 逻辑2:先从资源中读取背景资源,新建一个MEMDC,将绘图对象与MEMDC绑定,并且 // 通过绘图对象在内 ...
- 山东省第四届ACM程序设计竞赛A题:Rescue The Princess(数学+计算几何)
Rescue The Princess Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 412 Solved: 168[Submit][Status][ ...
- 计算机行业工作者-->面试的总结博文(【*持续补充】)
1.博文题目:找实习/工作经验心得分享-偏IT技术向 http://blog.csdn.net/koudaidai/article/details/8063288 2.博文题目:百度,阿里 笔试面试 ...
- 本地Ubuntu16搭建Seafile
本地搭建Seafile 1.下载 2.解压 3.创建目录 mySeafile 4.将解压包放入mySeafile中 5.创建installed 将压缩包放入installed 安装准备工作 pytho ...