POJ2411 Mondriaan's Dream 【状压dp】

#include <cstdio>
#include <cstring>

const int size = (1 << 15) +5;
typedef long long LL;
LL a[15][size];
int n, m;

void init(int d, int s) {
if(d == m+1) {
a[1][s] ++;
return ;
}

if( d <= m ) init(d+1, s << 1);
if( d < m ) init(d+2, s << 2 | 3);
}

void dfs(int d, int s1, int s2, int t) {
if(d == m+1) {
a[t][s1] += a[t-1][s2];
return ;
}
if(d <= m) {
dfs(d+1, s1 << 1 | 1, s2 << 1, t);
dfs(d+1, s1 << 1, s2 << 1 | 1, t);
}
if(d < m) dfs(d+2, s1 << 2|3, s2 << 2 | 3, t);
}

int swap(int &x, int &y) {
int t = x; x = y; y = t;
}

int main() {
while( scanf("%d %d", &n, &m), n+m ) {
if((n*m)%2) {
puts("0");
continue;
}
memset(a, 0, sizeof(a));
if(n > m) swap(n, m);
init(1, 0);
for ( int i = 2; i <= n; i ++ ) dfs(1, 0, 0, i);
printf("%lld\n", a[n][(1<<m)-1]);
}

return 0;
}

poj2411Mondriaan's Dream题解

2015-08-01 17:43:12

POJ2411:Mondriaan's Dream(状态压缩)

2014-05-04 22:44:33

POJ2411 - Mondriaan's Dream （状压DP+轮廓线DP）

2017-05-18 19:31:11

POJ-2411-Mondriaan's Dream-轮廓线dp（插头dp）

2016-08-09 00:31:52

poj 2411 Mondriaan's Dream(状态压缩dp)

2015-11-24 17:27:53

POJ2411——Mondriaan's Dream（轮廓线dp入门）

2016-08-03 20:12:01

pku 2411 Mondriaan's Dream dp 状态压缩

2010-05-31 19:03:00

poj2411--Mondriaan's Dream(状压dp+dfs)

2015-02-04 20:49:28

zoj 1100 - Mondriaan's Dream

2014-10-10 12:34:09

POJ 2411 铺地砖 状态压缩dp入门

2014-02-10 15:34:41