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. VMware虚拟机下安装RedHat Linux 9.0

    从这一篇文章开始我和大家一起学习Linux系统.不管是什么样的系统,必须安装上才能谈使用对吧. Linux版本 安装Linux之前需要了解一下Linux系统的安装版本. Linux的版本分为内核版本和 ...

  2. 九度OJ 1004:Median

    #include <stdio.h> #include <stdlib.h> #include <limits.h> #define N 1000000 int a ...

  3. SPDIF接口细则详解

    链接:https://max.book118.com/html/2017/0422/101658483.shtm

  4. API的理解和使用——单线程架构

    核心知识点: 1.单线程机制:所有命令放在一个队列中 2.为什么Redis单线程这么快?内存中执行.非IO阻塞.避免线程切换和竞态产生的消耗. 3.单线程的问题?一个命令不能执行太长时间,不然会阻塞其 ...

  5. 使用urllib2打开网页的三种方法(Python2)

    python2才有urllib2模块,python3把urllib和urllib2封装成了urllib模块 使用urllib2打开网页的三种方法 #coding:utf-8 import urllib ...

  6. ruby 精选网站

    ruby 基础   http://www.yiibai.com/ruby/2013/0820174.html     http://www.rubydoc.info/github       http ...

  7. 网页布局的应用(float或absolute)

    一个浮动(左浮动或右浮动) 垂直环绕布局(float.clear) 左右两列布局(float.absolute) 三栏网页宽度自适应布局(float.absolute) 注意:网页设计中应该尽量避免使 ...

  8. JavaMail发送和接收邮件

    一.JavaMail概述:        JavaMail是由Sun定义的一套收发电子邮件的API,不同的厂商可以提供自己的实现类.但它并没有包含在JDK中,而是作为JavaEE的一部分. 厂商所提供 ...

  9. 《CSS权威指南(第三版)》---第七章 基本视觉格式化

    主要知识记录: 1.给一个元素指定内容区宽度,如果设置了内边距,边框和外边距,这些因素都会影响CSS的width属性. 2.在水平格式化的7个属性中,width,margin-left,margin- ...

  10. c# wpf ComboBox 动态下拉框 及 动态默认值设定

    1.下拉框声明 <ComboBox x:Name="DirComboBox" Width="150" Height="18" Marg ...