码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 4804 Campus Design(经典轮廓线问题扩展)

时间:2015-08-10 00:21:41      阅读:98      评论:0      收藏:0      [点我收藏+]

标签:



题意:给定一个图,0是不能放的,然后现在有1X1和1X2方块,最后铺满该图,使得1X1使用次数在C到D之间,1X2次数随便,问有几种放法。

思路:经典问题多米诺的拓展,状态多开一维表示用了几个1*1砖块即可,注意位运算的优先级。

#include<cstdio>  
#include<cstring>  
#include<cmath>  
#include<cstdlib>  
#include<iostream>  
#include<algorithm>  
#include<vector>  
#include<map>  
#include<queue>  
#include<stack> 
#include<string>
#include<map> 
#include<set>
#define eps 1e-6 
#define LL long long  
#define pii (pair<int, int>)
//#pragma comment(linker, "/STACK:1024000000,1024000000") 
using namespace std;  
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
int n, m, cur, C, D;
const int maxn = 11;
LL d[2][1<<maxn][25];
char G[150][maxn];

int main() {
//	freopen("input.txt", "r", stdin);
	while(scanf("%d%d%d%d", &n, &m, &C, &D) == 4) {
		for(int i = 0; i < n; i++) {
			getchar();
			for(int j = 0; j < m; j++) scanf("%c", &G[i][j]);
		}
		cur = 0;
		memset(d[cur], 0, sizeof(d[cur])); 
		d[cur][(1<<m)-1][0] = 1;
		for(int i = 0; i < n; i++)
			for(int j = 0; j < m; j++) {
				cur ^= 1;
				memset(d[cur], 0, sizeof(d[cur]));
				for(int k = 0; k < (1<<m); k++) {
					if(G[i][j] == '1') {
						if((k&(1<<(m-1))) || (i&&G[i-1][j]=='0')) for(int l = 0; l <= D; l++)
								d[cur][(k<<1)&(~(1<<m))][l] += d[1-cur][k][l], d[cur][(k<<1)&(~(1<<m))][l] %= mod; //不放
						if(i && !(k&(1<<(m-1))) && G[i-1][j]!='0') for(int l = 0; l <= D; l++)
								d[cur][(k<<1)+1][l] += d[1-cur][k][l], d[cur][(k<<1)+1][l] %= mod; //竖放1*2 
						if(j && G[i][j-1]!='0' && !(k&1) && ((k&(1<<(m-1)))||i&&G[i-1][j]=='0')) for(int l = 0; l <= D; l++)
								d[cur][(k<<1)&(~(1<<m))|3][l] += d[1-cur][k][l], d[cur][(k<<1)&(~(1<<m))|3][l] %= mod; //右放1*2  
						if((k&(1<<(m-1))) || i&&G[i-1][j]=='0') for(int l = 0; l < D; l++)
								d[cur][((k<<1)&(~(1<<m)))+1][l+1] += d[1-cur][k][l], d[cur][((k<<1)&(~(1<<m)))+1][l+1] %= mod; //放1*1 
					}
					else {
						if((k&(1<<(m-1))) || i&&G[i-1][j]=='0') for(int l = 0; l <= D; l++)
							d[cur][(k<<1)&(~(1<<m))][l] += d[1-cur][k][l], d[cur][(k<<1)&(~(1<<m))][l] %= mod;
					}
				}
			} 
		LL ans = 0;
		int s = (1<<m)-1;
		for(int i = 0; i < m; i++) if(G[n-1][i] == '0') s ^= (1<<(m-i-1));
		//cout << s << endl;
		for(int i = C; i <= D; i++) ans += d[cur][s][i], ans %= mod;
		//cout << d[1-cur][s][0] << endl;
		cout << ans << endl;
		//for(int i = C; i <= D; i++) cout << d[1-cur][2][0] << endl;
		//cout << G[0][0] << G[0][1] << endl;
	}
	return 0;
}





版权声明:本文为博主原创文章,未经博主允许不得转载。

HDU 4804 Campus Design(经典轮廓线问题扩展)

标签:

原文地址:http://blog.csdn.net/u014664226/article/details/47382075

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!