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状态选到结束得 ...
随机推荐
- 九度OJ 1166:迭代求立方根 (迭代)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3695 解决:1700 题目描述: 立方根的逼近迭代方程是 y(n+1) = y(n)*2/3 + x/(3*y(n)*y(n)),其中y0 ...
- 不依赖外部js es 库 实现 点击内容 切换
<!DOCTYPE html> <html lang="zh-cmn-Hans"> <head> <meta http-equiv=&qu ...
- split_brain
脑裂 系统中两个或多个部分开始独立工作
- iOS 流布局 UICollectionView使用(UICollectionVIew的代理方法)
UICollectionViewDataSource协议 这个协议主要用于collectionView相关数据的处理,包含方法如下: 设置分区数(这个是可选实现的) - (NSInteger)numb ...
- Flask的Debug功能非常酷
Flask是一个Python开发框架.在试用的过程中发现它的debug功能非常cool.如下图所示,在出错的页面每条栈新的右边都有一个按钮,点击之后我们可以执行Python代码,而且非常重要的一点是通 ...
- CodeForces - 799B T-shirt buying 【贪心】
题目链接 http://codeforces.com/problemset/problem/799/B 题意 给出N件衣服 pi 表示 第i件衣服的价格 ai 表示 第i件衣服的前面的颜色 bi 表示 ...
- IOS平台的几个推送服务的对比
http://blog.163.com/scuqifuguang@126/blog/static/171370086201399113833299/ 最近研究了一下极光推送(JPush) ...
- Canvas动画按钮
在线演示 本地下载
- 练习E-R图书管理数据库
- erlang的map基本使用
maps 适用于需要在运行时改变数据结构(record则不行)的场景,可以动态增加key 数据量不宜过大,具体多大没有实际数据, maps from_list 如果list表很长,则相应的耗时时间会 ...