HDU - 1400 Mondriaan's Dream

Posted Wisdom+.+

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HDU - 1400 Mondriaan's Dream相关的知识,希望对你有一定的参考价值。

HDU - 1400

思路:

轮廓线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 = 15;
LL dp[2][1<<N], n, m, cur;
void update(int a, int b) {
    if(b & (1<<m))dp[cur][b^(1<<m)] += dp[1-cur][a];
}
int main() {
    while(~ scanf("%d%d", &n, &m) && n && m) {
        if(n < m) swap(n, m);
        mem(dp, 0);
        cur = 0;
        dp[0][(1<<m)-1] = 1;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                cur ^= 1;
                mem(dp[cur], 0);
                for (int k = 0; k < (1<<m); k++) {
                    update(k, k<<1);
                    if(i && !(k & (1<<m-1))) update(k, (k<<1)^(1<<m)^1);
                    if(j && !(k & 1)) update(k, (k<<1)^3);
                }

            }
        }
        printf("%lld\n", dp[cur][(1<<m)-1]);
    }
    return 0;
}

 

以上是关于HDU - 1400 Mondriaan's Dream的主要内容,如果未能解决你的问题,请参考以下文章

POJ2411 Mondriaan's Dream

[POJ2411]Mondriaan's Dream

poj2411 Mondriaan's Dream状压DP

POJ 2411Mondriaan's Dream(状压dp)

[poj P2411] Mondriaan's Dream

POJ 2411Mondriaan's Dream