Campus Design

Nanjing University of Science and Technology is celebrating its 60th anniversary. In order to make room for student activities, to make the university a more pleasant place for learning, and to beautify the campus, the college administrator decided to start construction on an open space. 
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)的更多相关文章

  1. HDU 4804 Campus Design

    HDU 4804 思路: 轮廓线dp #include<bits/stdc++.h> using namespace std; #define fi first #define se se ...

  2. $POJ2411\ Mondriaan's\ Dream$ 状压+轮廓线$dp$

    传送门 Sol 首先状压大概是很容易想到的 一般的做法大概就是枚举每种状态然后判断转移 但是这里其实可以轮廓线dp 也就是从上到下,从左到右地放方块 假设我们现在已经放到了$(i,j)$这个位置 那么 ...

  3. HDU - 4804 Campus Design 轮廓线dp

    题意:一个nm的矩阵被12的骨牌和11的骨牌完全覆盖,11的骨牌只能放c-d次,矩阵中有障碍物 题解:dp[i][j][k]表示到了第i行,第j个状态,放过k个11的骨牌,当前位有障碍物时只有一种转移 ...

  4. hdu 3247 AC自动+状压dp+bfs处理

    Resource Archiver Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 100000/100000 K (Java/Ot ...

  5. hdu 2825 aC自动机+状压dp

    Wireless Password Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  6. HDU 5765 Bonds(状压DP)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5765 [题目大意] 给出一张图,求每条边在所有边割集中出现的次数. [题解] 利用状压DP,计算不 ...

  7. HDU 4281 Judges' response 状压dp+多旅行商问题

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4281 Judges' response Time Limit: 2000/1000 MS (Java ...

  8. hdu 3681(bfs+二分+状压dp判断)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3681 思路:机器人从出发点出发要求走过所有的Y,因为点很少,所以就能想到经典的TSP问题.首先bfs预 ...

  9. hdu 4778 Gems Fight! 状压dp

    转自wdd :http://blog.csdn.net/u010535824/article/details/38540835 题目链接:hdu 4778 状压DP 用DP[i]表示从i状态选到结束得 ...

随机推荐

  1. Elasticsearch基本语法

    match和match_phrase区别 match: 索引中只要有任意一个匹配拆分后词就可以出现在结果中,只是匹配度越高的排越前面 match_phrase: 索引中必须同时匹配拆分后词就可以出现在 ...

  2. display:inline

    一.基本介绍 它可以让行内显示为块的元素,变为行内显示,例如 <div> DIV1 </div> <div> DIV2 </div> 这里DIV1和DI ...

  3. x86 寻址学习

    x86 寻址方式众多,什么直接寻址.间接寻址.基址寻址.基址变址寻址等等让人眼花缭乱,而 AT&T 语法对内存寻址方式做了一个很好的统一,其格式为 section:displacement(b ...

  4. valgrind报错VEX temporary storage exhausted

    valgrind的使用请参考: 使用valgrind进行内存泄漏和非法内存操作检测 最近在使用valgrind进行内存泄漏检测是时,竟然报错,如下: VEX temporary storage exh ...

  5. python中的编码转换

    今天遇到了一个问题,将字符串“\uxxxx\uxxxx”转换成汉字.网上查了很多资料都不行. 后来看到,发现一个函数就OK了. str = str.decode('unicode_escape') 等 ...

  6. <JAVA8新增内容>关于匿名内部集合和lambda表达式

    要想说清楚JAVA中的Lambda表达式,必须想讲一下匿名内部类来帮助理解本质. 一.匿名内部类 匿名内部类适合创建那种只需要一次使用的类,例如前面介绍命令模式时所需要的Command对象,匿名内部类 ...

  7. POJ3415 Common Substrings —— 后缀数组 + 单调栈 公共子串个数

    题目链接:https://vjudge.net/problem/POJ-3415 Common Substrings Time Limit: 5000MS   Memory Limit: 65536K ...

  8. 部署nginx支持lua

    nginx yum -y install gcc pcre pcre-devel openssl openssl-devel  GeoIP GeoIP-devel lua lua-develwget ...

  9. BZOJ 1529 [POI2005]ska Piggy banks:并查集

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1529 题意: Byteazar有N个小猪存钱罐. 每个存钱罐只能用钥匙打开或者砸开. By ...

  10. 存储过程之rowtype 使用

    CREATE OR REPLACE PROCEDURE "DYLYLQX_SC_BA_1" (YWID IN VARCHAR2, FLAG OUT VARCHAR2) IS V_R ...