POJ 2411 Mondriaan's Dream 状压dp
2017-04-21 22:00
85 查看
题目链接:
https://vjudge.net/contest/159644#problem/G题意:
用1*2的砖去恰好铺满n*m的空间,有多少种方法题解:
http://blog.csdn.net/xingyeyongheng/article/details/21692655代码:
#include <iostream> #include <cstdio> #include <cstring> using namespace std; typedef long long ll; #define MS(a) memset(a,0,sizeof(a)) #define MP make_pair #define PB push_back const int INF = 0x3f3f3f3f; const ll INFLL = 0x3f3f3f3f3f3f3f3fLL; inline ll read(){ ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } ////////////////////////////////////////////////////////////////////////// const int maxn = (1<<11)+10; int n,m; ll cnt[maxn],dp[maxn]; bool mark[maxn]; bool check(int x){ while(x){ if(x&1){ x >>= 1; if(!(x&1)) return false; x >>= 1; }else { x >>= 1; } } return true; } void init(){ MS(mark); MS(cnt); for(int i=0; i<(1<<m); i++){ if(check(i)) cnt[i]=1,mark[i]=true; } } void DP(){ for(int k=2; k<=n; k++){ MS(dp); for(int i=0; i<(1<<m); i++){ // 枚举本行的状态 for(int j=0; j<(1<<m); j++){ // 枚举上一行的状态,找到可以转移到第i行的状态 if((i|j) != (1<<m)-1) continue; if(!mark[i&j]) continue; dp[i] += cnt[j]; //i可以从j到达,则增加j的方案数 // mark[i&j] 是为了判断两行都是横着放的状态---> 1 1 // 1 1 // 如果是 i = 00110011 // j = 11011111 i&j=00010011 这是不合法的 } } for(int i=0; i<(1<<m); i++) cnt[i] = dp[i]; } } int main(){ while(cin>>n>>m && (n+m)){ if(n<m) swap(n,m); //始终保持m<n,提高效率 init(); DP(); cout << cnt[(1<<m)-1] << endl; //输出最后一行到达时的状态必须全部是1 } return 0; } // http://blog.csdn.net/xingyeyongheng/article/details/21692655[/code]
相关文章推荐
- Mondriaan's Dream - POJ 2411 状压dp
- Poj 2411 Mondriaan's Dream(压缩矩阵DP)
- POJ 2411 Mondriaan's Dream(插头DP,轮廓线)
- 【poj 2411】Mondriaan's Dream 状态压缩DP
- L - Mondriaan's Dream POJ - 2411
- poj 2411 Mondriaan's Dream(状态压缩dp)
- POJ2411 Mondriaan's Dream (轮廓线动态规划典型例题 以及用状态压缩逐行深搜推的方法)
- POJ 2411 Mondriaan's Dream(状压DP)
- POJ 2411 Mondriaan's Dream
- POJ 2411 Mondriaan's Dream(状态DP)
- Chapter06-Mondriaan's Dream(POJ 2411)(状态压缩DP)
- poj 2411 Mondriaan's Dream(状态压缩dp)
- POJ 2411 Mondriaan's Dream 状态压缩(DP)
- Mondriaan's Dream POJ - 2411 (状压dp,轮廓线dp)
- POJ 2411 Mondriaan's Dream(状态压缩)
- poj 2411 Mondriaan's Dream
- [POJ] 2411 Mondriaan's Dream
- Poj 2411 Mondriaan's Dream(状压DP)
- POJ 2411 Mondriaan'sDream(状压DP)
- POJ 2411 && HDU 1400 Mondriaan's Dream(状态压缩DP)