DFS+DP压缩状态,二进制优化处理
#include <stdio.h>
#include <string.h>
long long a[2][1<<11];
int n, m, t;
void init(int d, int last)
{
if ( d == m )
{
a[0][last]++;
return;
}
if ( d+1 <= m )
init(d+1, last<<1);
if ( d+2 <= m )
init(d+2, last<<2|3);
}
void dfs( int d, int last, int now )
{
if ( d == m )
{
a[t][now] += a[(t+1)%2][last];
return;
}
if ( d+1 <= m)
{
dfs(d+1, last<<1, now<<1|1);
dfs(d+1, last<<1|1, now<<1);
}
if ( d+2 <= m)
{
dfs(d+2, last<<2|3, now<<2|3);
}
}
int main ()
{
while ( scanf("%d%d", &n, &m), n&&m )
{
if ( m*n%2 )
{
printf("0\n");
continue;
}
if ( n > m )
{
int t= m;
m= n;
n= t;
}
memset( a, 0, sizeof(a) );
init(0,0);
for ( int i = 2; i <= n; i++ )
{
t=(i+1)%2;
dfs(0, 0, 0);
memset( a[(t+1)%2], 0, sizeof(a[0]) );
}
printf("%lld\n", a[(n+1)%2][(1<<m)-1]);
}
return 0;
}