思路:
轮廓线dp
#include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pi acos(-1.0) #define LL long long //#define mp make_pair #define pb push_back #define ls rt<<1, l, m #define rs rt<<1|1, m+1, r #define ULL unsigned LL #define pll pair<LL, LL> #define pii pair<int, int> #define mem(a, b) memset(a, b, sizeof(a)) #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout); //head const int N = 12; const int MOD = 1e9 + 7; int dp[2][1<<N][25]; int n, m, cur; char mp[105][N]; void update(int a, int b, int t) { if(b & (1<<m)) dp[cur][b^(1<<m)][t] += dp[1-cur][a][t-1], dp[cur][b^(1<<m)][t] %= MOD; } void Update(int a, int b, int t) { if(b & (1<<m)) dp[cur][b^(1<<m)][t] += dp[1-cur][a][t], dp[cur][b^(1<<m)][t] %= MOD; } int main() { int c, d; while(~scanf("%d%d%d%d", &n, &m, &c, &d)) { for (int i = 0; i < n; i++) scanf("%s", mp[i]); cur = 0; mem(dp, 0); dp[cur][(1<<m)-1][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cur ^= 1; mem(dp[cur], 0); if(mp[i][j] == '1') { for(int k = 0; k < (1<<m); k++) { for (int l = 0; l <= d; l++) { Update(k, (k<<1), l); if(l)update(k, (k<<1)^1, l); if(i && !(k & (1<<m-1))) Update(k, (k<<1)^(1<<m)^1, l); if(j && !(k & 1)) Update(k, (k<<1)^3, l); } } } else { for (int k = 0; k < (1<<m); k++) { for (int l = 0; l <= d; l++) { Update(k, (k<<1)^1, l); } } } } } LL ans = 0; for (int i = c; i <= d; i++) ans += dp[cur][(1<<m)-1][i], ans %= MOD; printf("%lld ", ans); } return 0; }