题意:用1*2的骨牌覆盖n*m的棋盘有多少种方法
这道题注意一下不要按照大白书上把maxn开成15就好,因为每次都要memset如果开到15会tle,开到11就可以
#include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<iostream> #include<algorithm> #include<vector> #include<map> #include<queue> #include<stack> #include<string> #include<map> #include<set> #define eps 1e-6 #define LL long long #define pii (pair<int, int>) //#pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; //const int INF = 0x3f3f3f3f; //freopen("input.txt", "r", stdin); int n, m, cur; const int maxn = 11; LL d[2][1<<maxn]; int main() { while(scanf("%d%d", &n, &m) == 2) { if(m > n) swap(m, n); cur = 0; memset(d[cur], 0, sizeof(d[cur])); d[cur][(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++) { if(k&(1<<(m-1))) d[cur][(k<<1)^(1<<m)] += d[1-cur][k]; //不放 if(i && !(k&(1<<(m-1)))) d[cur][(k<<1)+1] += d[1-cur][k]; if(j && !(k&1) && (k&(1<<(m-1)))) d[cur][(k<<1)^(1<<m)|3] += d[1-cur][k]; } } LL ans = d[cur][(1<<m)-1]; printf("%lld\n", ans); } return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
UVA 11270 Tiling Dominoes(轮廓线DP经典)
原文地址:http://blog.csdn.net/u014664226/article/details/47378889