标签:
轮廓线dp 骨牌覆盖问题 n和m比较小
1 #pragma comment(linker, "/STACK:102400000,102400000") 2 3 #include <cstdio> 4 #include <cstdlib> 5 #include <cstring> 6 #include <cmath> 7 #include <ctime> 8 #include <iostream> 9 #include <algorithm> 10 #include <queue> 11 #include <map> 12 #include <set> 13 #include <vector> 14 #include <list> 15 #include <stack> 16 #include <string> 17 18 using namespace std; 19 20 #define PI acos(-1.0) 21 #define INF 0x3f3f3f3f 22 #define inf 0x3f 23 #define rst(a, b) memset(a, b, sizeof(a)) 24 #define mod 1000000007 25 #define eps 1e-6 26 #define ok puts("ok"); 27 28 typedef long long ll; 29 typedef unsigned long long ull; 30 typedef pair<int, int> pii; 31 32 const int maxn = 200005; 33 const int maxm = 10005; 34 35 int dp[2][16]; 36 int n, m = 4, cur; 37 38 void update(int a, int b) { 39 if(b & (1<<m)) dp[cur][b^(1<<m)] += dp[1-cur][a]; 40 } 41 42 void solve() { 43 int cases; 44 scanf("%d", &cases); 45 for(int idx = 1; idx <= cases; idx++) { 46 scanf("%d", &n); 47 cur = 0; 48 rst(dp, 0); 49 dp[0][(1<<m)-1] = 1; 50 for(int i = 0; i < n; i++) { 51 for(int j = 0; j < m; j++) { 52 cur ^= 1; 53 rst(dp[cur], 0); 54 for(int k = 0; k < (1<<m); k++) { 55 update(k, k<<1); 56 if(i && !(k&(1<<(m-1)))) update(k, (k<<1)^(1<<m)^1); 57 if(j && !(k&1)) update(k, (k<<1)^3); 58 } 59 } 60 } 61 printf("%d %d\n", idx, dp[cur][(1<<m)-1]); 62 } 63 } 64 65 int main() { 66 solve(); 67 return 0; 68 }
标签:
原文地址:http://www.cnblogs.com/mitrenick/p/4833368.html