UVA 11270 轮廓线
题目链接:
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33787
题意:
用1*2或2*1的长条把n*m方格铺满的方案数。裸的轮廓线dp。
代码:
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 using namespace std; 5 6 const int maxn = 111; 7 typedef long long LL; 8 9 LL dp[2][1 << 11]; 10 int n, m,cur; 11 12 void update(int a, int b) { 13 if (b&(1 << m)) dp[cur][b ^ (1 << m)] += dp[1 - cur][a]; 14 } 15 16 int main() { 17 while (scanf("%d%d", &n, &m) == 2 && n) { 18 if (m>n) swap(n, m); 19 memset(dp, 0, sizeof(dp)); 20 dp[0][(1 << m) - 1] = 1; cur = 0; 21 for (int i = 0; i < n; i++) { 22 for (int j = 0; j < m; j++) { 23 cur = 1 - cur; 24 memset(dp[cur], 0, sizeof(dp[cur])); 25 for (int k = 0; k < (1 << m); k++) { 26 update(k, k << 1); 27 if (i && !(k&(1 << m - 1))) { 28 update(k, (k << 1) ^ 1 ^ (1 << m)); 29 } 30 if (j&&!(k & 1)) { 31 update(k, (k << 1) ^ 3); 32 } 33 } 34 } 35 } 36 printf("%lld\n", dp[cur][(1 << m) - 1]); 37 } 38 return 0; 39 }