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

HDU - 1400 Mondriaan's Dream

时间:2018-05-27 14:51:22      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:tps   i++   const   get   void   lan   lld   can   false   

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

标签:tps   i++   const   get   void   lan   lld   can   false   

原文地址:https://www.cnblogs.com/widsom/p/9095892.html

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