题意:用1 x 2的块恰好填满m x n的矩形有多少种填法。(m*n < 101)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33787
——>>轮廓线dp。注意maxn不要太大,开始用15,结果TLE,改成11后AC。
#include <cstdio>
#include <algorithm>
#include <cstring>using namespace std;const int maxn = 11;
int n, m, cur;
long long d[2][1<<maxn];void update(int a, int b)
{if(b&(1<<m)) d[cur][b^(1<<m)] += d[1-cur][a];
}int main()
{while(scanf("%d%d", &m, &n) == 2){if(m > n) swap(m, n);memset(d, 0, sizeof(d));cur = 0;d[0][(1<<m)-1] = 1;for(int i = 0; i < n; i++)for(int j = 0; j < m; j++){cur ^= 1;memset(d[cur], 0, sizeof(d[cur]));for(int k = 0; k < (1<<m); k++){update(k, k<<1);if(i && !(k&(1<<(m-1)))) update(k, (k<<1)^(1<<m)^1);if(j && !(k&1)) update(k, (k<<1)^3);}}printf("%lld\n", d[cur][(1<<m)-1]);}return 0;
}