标签:
#include <cstdio> #include <cstring> typedef __int64 LL; LL dp[10][1<<10]; int n, m; int st, flag; void dfs(int i, int s, int ns, int j, LL num) { if(j == m) { dp[i+1][ns] += num; return; } if((s&(1<<j)) == 0) { if(ns&(1<<j)) { if(j+1 < m) { if((s&(1<<(j+1))) == 0) { dfs(i, s|(1<<j)|(1<<(j+1)), ns|(1<<(j+1)), j+2, num); //dfs(i, s|(1<<j)|(1<<(j+1)), ns, j+1, num); } } } else { dfs(i, s|(1<<j), ns|(1<<j), j+1, num); if(j+1 < m) { dfs(i, s|(1<<j), ns|(1<<j)|(1<<(j+1)), j+1, num); if((s&(1<<(j+1))) == 0) { dfs(i, s|(1<<j)|(1<<(j+1)), ns|(1<<j), j+1, num); dfs(i, s|(1<<j)|(1<<(j+1)), ns|(1<<(j+1)), j+1, num); } } } } else { if(ns&(1<<j)) { dfs(i, s, ns, j+1, num); } else { dfs(i, s, ns, j+1, num); if(j+1 < m) { if((s&(1<<(j+1))) == 0) { dfs(i, s|(1<<(j+1)), ns|(1<<j)|(1<<(j+1)), j+2, num); } dfs(i, s, ns|(1<<j)|(1<<(j+1)), j+1, num); } } } } int main() { while(scanf("%d %d", &n, &m) != EOF) { memset(dp, 0, sizeof(dp)); dp[0][(1<<m)-1] = 1; flag = 0; for(int i = 0; i < n; i++) { for(int j = 0; j < (1<<m); j++) if(dp[i][j] > 0) { st = j; dfs(i, j, 0, 0, dp[i][j]); } } printf("%I64d\n", dp[n][(1<<m)-1]); } return 0; }
标签:
原文地址:http://blog.csdn.net/u011686226/article/details/44017873