题意:用1 x 2的矩形铺w * h的矩形,有多少种铺法。(1 <= h, w <= 11)
题目链接: http://poj.org/problem?id=2411
——>>轮廊线dp。
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn = 12;
int h, w, cur;
long long d[2][1<<maxn];
void update(int a, int b)
{
if(b&(1<<w)) d[cur][b^(1<<w)] += d[1-cur][a];
}
int main()
{
while(scanf("%d%d", &w, &h) == 2)
{
if(!w && !h) return 0;
if(w > h) swap(w, h);
memset(d, 0, sizeof(d));
cur = 0;
d[0][(1<<w)-1] = 1;
for(int i = 0; i < h; i++)
for(int j = 0; j < w; j++)
{
cur ^= 1;
memset(d[cur], 0, sizeof(d[cur]));
for(int k = 0; k < (1<<w); k++)
{
update(k, k<<1);
if(i && !(k&(1<<(w-1)))) update(k, (k<<1)^(1<<w)^1);
if(j && !(k&1)) update(k, (k<<1)^3);
}
}
printf("%I64d\n", d[cur][(1<<w)-1]);
}
return 0;
}