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状态选到结束得 ...
随机推荐
- python知识点导图(搜集)
第一章 基本环境 第二章 内置类型 第三章 表达式 第四章 函数 第五章 迭代器 第六章 模块 第七章 类 第八章 异常 第九章 装饰器 第十章 描述符 第十一章 元类 第十二章 标准库 Re模块 附 ...
- HttpClient 访问 https 出现peer can't
package util; import java.security.cert.CertificateException; import javax.net.ssl.SSLContext;import ...
- mysql系列之3.mysql进阶
启动原理 mysqld脚本-->mysqld_safe脚本-->mysqld服务-->启动mysql 强制关闭mysql: 三种方法, 不建议用! killall mysqld pk ...
- 中文WebFont探索
本文主要讲中文webFont的相关知识,包含了业界现状.WebFont优势.实现方案等. 一 业界使用WebFont现状 1.1 英文WebFont使用现状 英文版已使用非常广泛.比较有名的字体库:G ...
- VC里OnPaint几点要注意的地方(没有invalidate,系统认为窗口没有更新的必要,于是就对发来的WM_PAINT消息不理不睬)
写在属于自己的体会,哪怕只是一点点,也是真的懂了.否则有那么多书,如果只是不过脑子的学一遍看一遍,又有谁真的掌握了这些知识呢? 这样你或许就明白了为什么不能直接用SendMessage和PostMes ...
- 【题解】数字组合(NTT+组合 滑稽)
[题解]数字组合(NTT+组合 滑稽) 今天实践一下谢总讲的宰牛刀233,滑稽. \((1+x)(1+x)(1+x)\)的\(x^2\)系数就代表了有三个一快钱硬币构成的两块钱的方案数量. 很好理解, ...
- 【题解】[P3557 POI2013]GRA-Tower Defense Game
[题解][P3557 POI2013]GRA-Tower Defense Game 这道题是真的** 根据题目给的\(k\),可以知道,我们随便放塔,只要不全放一起,一定是一种合法的方案. 直接枚举就 ...
- 我的Android进阶之旅------>Android实现音乐示波器、均衡器、重低音和音场功能
本实例来自于<疯狂Android讲义>,要实现具体的功能,需要了解以下API: MediaPlayer 媒体播放器 Visualizer 频谱 Equalizer 均衡器 BassBoo ...
- C语言实现 操作系统 银行家算法
/**************************************************** 银行家算法 算法思想: 1. 在多个进程中,挑选资源需求最小的进程Pmin. 可能存在多类资 ...
- python 函数中的递归、lambda 、map reduce 等详解
举例说明 #例1: ###递归函数求和 from traitlets.traitlets import Instance def mysum(L): print(L) if not L: return ...