Created
September 5, 2012 15:48
-
-
Save iloahz/3638788 to your computer and use it in GitHub Desktop.
POJ 2411 Mondriaan's Dream by iloahz@Attiix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <cstring> | |
#include <algorithm> | |
using namespace std; | |
const int MAXN = 12; | |
const int MAXS = 2048; | |
int h, w; | |
long long f[2][MAXS]; | |
long long dp(int m, int n){ | |
int s = 1 << m; | |
int l = 0, r = 1; | |
memset(f, 0, sizeof(f)); | |
f[l][0] = 1; | |
for (int i = 0;i < n;i++){ | |
for (int j = 0;j < s;j++) f[r][j] = 0; | |
for (int j = 0;j < s;j++){ | |
if (f[l][j]){ | |
for (int k = 0;k < s;k++){ | |
if ((k & j) == 0){ | |
int x = j | k; | |
for (int p = 3;p < s;p <<= 1) | |
if ((x & p) == 0) x |= p; | |
if (x + 1 == s) f[r][k] += f[l][j]; | |
} | |
} | |
} | |
} | |
l ^= 1; | |
r ^= 1; | |
} | |
return f[l][0]; | |
} | |
int main(){ | |
#ifdef ATTIIX | |
freopen("pku2411.in", "r", stdin); | |
#endif | |
while (~scanf("%d%d", &h, &w) && (h > 0)){ | |
printf("%lld\n", dp(h, w)); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment