#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; int n, m, pre = 0, now = 1; long long dp[2][2222]; int main() { while (~scanf("%d%d", &n, &m)) { if (n<m) swap(n,m); int maxs = (1<<m); memset(dp[now], 0, sizeof(dp[now])); dp[now][maxs - 1] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { swap(pre, now); memset(dp[now], 0, sizeof(dp[now])); for (int s = 0; s < maxs; s++) { if (j && !(s&1<<(j-1)) && (s&1<<j)) //横放的情况 dp[now][s|1<<(j-1)] += dp[pre][s]; dp[now][s^1<<j] += dp[pre][s];//竖放的情况 } } } printf("%lld\n", dp[now][maxs - 1]); } return 0; }
UVA 11270 Tiling Dominoes(插头DP),布布扣,bubuko.com
UVA 11270 Tiling Dominoes(插头DP)
原文:http://blog.csdn.net/accelerator_/article/details/26096155