18. 涛酱和策策的游戏again

题目链接:涛酱和策策的游戏again

状压,枚举 m m m 这一维,压 n n n 这一维从上一层伸过来的那些格子的位置。可以先预处理出没有障碍的情况下的可行状态,转移的时候枚举上一位伸下来和这一维伸下去的情况,如果不与障碍物冲突的情况且剩下的格子可以被横的填满就可以转移。

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define endl '\n'
using ll = long long;
using pii = pair<int, int>;
const int maxn = 2048;
int chk[maxn], block[20];
ll dp[12][maxn];
void solve() {
	int n, m, k;
    while (cin >> n >> m >> k) {
        if (!n || !m)
            break;
        memset(block, 0, sizeof(block));
        int tot = (1 << n);
        for (int i = 1, x, y; i <= k; ++i) {
        	cin >> x >> y;
        	block[y] |= (1 << (x - 1));
        }
        // check [|] from last row
        for (int st = 0; st < tot; ++st) {
            int cnt = 0;
            chk[st] = 1;
            for (int i = 0; i < n; ++i) {
                if (st & (1 << i)) {
                    if (cnt & 1) {
                        chk[st] = 0;
                        break;
                    }
                    cnt = 0;
                } else {
                    cnt++;
                }
            }
            if (cnt & 1)
                chk[st] = 0;
        }
        memset(dp, 0, sizeof(dp));
        dp[0][0] = 1;
        for (int i = 1; i <= m; ++i) {
        	// last
            for (int j = 0; j < tot; ++j) {
            	// now
            	if (j & block[i]) continue;
                for (int s = 0; s < tot; ++s) {
                	int t = j | block[i];
                	if (!(t & s) && chk[t | s])
                        dp[i][s] += dp[i - 1][j];
                }
            }
        }
        cout << dp[m][0] << endl;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值