Skip to content

Instantly share code, notes, and snippets.

@iloahz
Created September 5, 2012 15:29
Show Gist options
  • Save iloahz/3638445 to your computer and use it in GitHub Desktop.
Save iloahz/3638445 to your computer and use it in GitHub Desktop.
ZOJ 2563 Long Dominoes by iloahz@Attiix
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 31;
const int MAXS = 512;
int n, m;
long long f[2][MAXS][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][0] = 1;
for (int i = 0;i < n;i++){
for (int j = 0;j < s;j++){
for (int k = 0;k < s;k++){
f[r][j][k] = 0;
}
}
for (int j = 0;j < s;j++){
for (int k = 0;k < s;k++){
if (f[l][j][k]){
for (int b = 0;b < s;b++){
if ((b & j) == 0 && (b & k) == 0){
int x = j | b;
for (int p = 7;p < s;p <<= 1)
if ((x & p) == 0) x |= p;
if (x + 1 == s) f[r][k | b][b] += f[l][j][k];
}
}
}
}
}
l ^= 1;
r ^= 1;
}
return f[l][0][0];
}
int main(){
#ifdef ATTIIX
freopen("zju2563.in", "r", stdin);
#endif
while (~scanf("%d%d", &m, &n) && (n > 0)){
printf("%lld\n", dp(m, n));
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment