#pragma GCC optimize(2)
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
int n, m, yy[1<<12];
ll dp[12][1<<12];
void init() {
ll mx = 1<<11;
for(ll i = 0; i < mx; i++) {
ll t = i, flag = 0;
while(t) {
if(t&1) flag = !flag;
else if(flag) break;
t /= 2;
}
if(!flag) yy[i] = 1;
}
}
bool check(ll x, ll y) {
if((x|y) != (1<<m)-1) return false;
ll t = x&y;
return yy[t];
}
void solve() {
if((n*m)&1) {
printf("0\n");
return;
}
memset(dp, 0, sizeof(dp));
ll mx = 1<<m;
for(ll i = 0; i < mx; i++)
if(yy[i]) dp[1][i] = 1;
for(int i = 2; i <= n; i++) {
for(ll j = 0; j < mx; j++) {
for(ll k = 0; k < mx; k++) {
if(check(j, k))
dp[i][j] += dp[i-1][k];
}
}
}
printf("%lld\n", dp[n][(1<<m)-1]);
return;
}
int main() {
init();
while(scanf("%d%d", &n, &m) == 2 && n+m) {
solve();
}
return 0;
}
poj2411【状压dp】
最新推荐文章于 2022-07-11 12:07:29 发布