题意:给定一个n*m的矩阵,矩阵中有些是障碍点有些是空位置,要求用1*1和1*2的骨牌覆盖整个矩阵并且1*1的骨牌使用的个数在[c,d]之间,求方案数。
分析:比较裸的轮廓线dp,直接设dp[i][j][mask][k]表示填到第i行第j列后状态为mask并且1*1使用了k个的方案数。O(n*m*2^m*d)
代码:
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<vector>
#include<string>
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=12;
const int mod=1000000007;
const int MOD1=1000000007;
const int MOD2=1000000009;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=1000000007;
const int INF=1000000010;
const ll MAX=1000000000;
const double pi=acos(-1.0);
typedef double db;
typedef unsigned long long ull;
char ma[N*N][N];
int e[N],dp[2][1<<N][25];
int main()
{
int i,j,k,h,n,m,c,d,mx,now,pre,ans;
for (e[0]=1,i=1;i<N;i++) e[i]=e[i-1]*2;
while (scanf("%d%d%d%d", &n, &m, &c, &d)!=EOF) {
for (i=0;i<n;i++) scanf("%s", ma[i]);
now=pre=0;mx=(1<<m)-1;
memset(dp[now],0,sizeof(dp[now]));
dp[now][mx][0]=1;
for (i=0;i<n;i++)
for (j=0;j<m;j++) {
pre=now;now^=1;
memset(dp[now],0,sizeof(dp[now]));
if (ma[i][j]=='1') {
for (k=0;k<=mx;k++)
if (k&e[j]) {
for (h=0;h<d;h++) (dp[now][k][h+1]+=dp[pre][k][h])%=mod;
if (j&&!(k&e[j-1])) {
for (h=0;h<=d;h++) (dp[now][k^e[j-1]][h]+=dp[pre][k][h])%=mod;
}
for (h=0;h<=d;h++) (dp[now][k^e[j]][h]+=dp[pre][k][h])%=mod;
} else if (i) {
for (h=0;h<=d;h++) (dp[now][k^e[j]][h]+=dp[pre][k][h])%=mod;
}
} else {
for (k=0;k<=mx;k++)
if (k&e[j]) {
for (h=0;h<=d;h++) (dp[now][k][h]+=dp[pre][k][h])%=mod;
}
}
}
for (ans=0,i=c;i<=d;i++) (ans+=dp[now][mx][i])%=mod;
printf("%d\n", (ans+mod)%mod);
}
return 0;
}