POJ - 2411 Mondriaan's Dream(状态压缩DP)
来源:互联网 发布:短域名生成 编辑:程序博客网 时间:2024/05/23 16:01
思路:状压DP
#include<iostream>#include<cstdio>#include<cstring>using namespace std;const int maxn = 12;#define LL long longLL dp[2][(1<<15)];int path[(1<<12)*(1<<12)][2];int w;void get(int m) { for(int i = 0;i<(1<<m);i++){for(int j = 0;j<(1<<m);j++){bool ok = true; for(int k = 0;k<m;k++) { if((i&(1<<k))==0) { if((j&(1<<k))==0){ok = false;break;}}else { if((j&(1<<k))==0) continue;k++;if((i&(1<<(k-1)) && !(i&(1<<k))) || k>=m) {ok = false;break;} else { if((j&(1<<k))==0 && j&(1<<(k-1))) { ok = false; break; } /*if(j&(1<<k) && !(j&(1<<(k-1)))) { k--; }*/}}}if(ok){path[w][0]=i;path[w++][1]=j;}}}}int main(){ int n,m;while(scanf("%d%d",&n,&m)!=EOF && (n+m)){w=0;if(n<m)swap(n,m);get(m);memset(dp,0,sizeof(dp));dp[0][(1<<m)-1]=1;int cur = 0;for(int i = 0;i<n;i++){cur^=1;memset(dp[cur],0,sizeof(dp[cur]));for(int j = 0;j<w;j++){dp[cur][path[j][1]]+=dp[1-cur][path[j][0]];}}printf("%lld\n",dp[cur][(1<<m)-1]);}}
Description
Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series' (where he had to use his toilet paper to draw on, for all of his paper was filled with squares and rectangles), he dreamt of filling a large rectangle with small rectangles of width 2 and height 1 in varying ways.
Expert as he was in this material, he saw at a glance that he'll need a computer to calculate the number of ways to fill the large rectangle whose dimensions were integer values, as well. Help him, so that his dream won't turn into a nightmare!
Expert as he was in this material, he saw at a glance that he'll need a computer to calculate the number of ways to fill the large rectangle whose dimensions were integer values, as well. Help him, so that his dream won't turn into a nightmare!
Input
The input contains several test cases. Each test case is made up of two integer numbers: the height h and the width w of the large rectangle. Input is terminated by h=w=0. Otherwise, 1<=h,w<=11.
Output
For each test case, output the number of different ways the given rectangle can be filled with small rectangles of size 2 times 1. Assume the given large rectangle is oriented, i.e. count symmetrical tilings multiple times.
Sample Input
1 21 31 42 22 32 42 114 110 0
Sample Output
10123514451205
0 0
- POJ 2411 Mondriaan's Dream 状态压缩(DP)
- poj 2411 Mondriaan's Dream (状态压缩dp 入门)
- POJ 2411 Mondriaan's Dream (状态压缩DP)
- poj 2411 Mondriaan's Dream(状态压缩DP)
- POJ 2411 Mondriaan's Dream (dp + 状态压缩)
- poj 2411 Mondriaan's Dream (状态压缩dp)
- poj 2411 Mondriaan's Dream(状态压缩+dp)
- POJ - 2411 Mondriaan's Dream(状态压缩DP)
- poj 2411 Mondriaan's Dream(状态压缩DP)
- poj 2411 Mondriaan's Dream(状态压缩dp)
- poj 2411 Mondriaan's Dream (状态压缩dp)
- POJ 2411 Mondriaan's Dream 状态压缩DP
- POJ 2411 Mondriaan's Dream 状态压缩dp
- POJ 2411 Mondriaan's Dream(DP---状态压缩)
- poj 2411/hdu 1400 Mondriaan's Dream 状态压缩dp
- HDOJ 1400 & POJ 2411 - Mondriaan's Dream 状态压缩DP
- poj 2411 Mondriaan's Dream(状态压缩dp)
- [poj 2411]Mondriaan's Dream[状态压缩DP]
- Leetcode 之 Unique Paths
- 使用git从本地上传至git码云远程仓库
- android studio配置lambda教程
- Java反射机制
- RabbitMQ基础学习笔记(C#代码示例)
- POJ - 2411 Mondriaan's Dream(状态压缩DP)
- Java Web基础——Action+Service +Dao三层的功能划分
- ScrollView嵌套ViewPager问题解决方案
- Intel汇编语言程序设计学习-第三章 汇编语言基础-下
- 最大似然估计、最大后验估计、贝叶斯估计
- Java多线程四:线程间通信/等待唤醒机制
- Day10、指针与函数、数组
- A. Hulk
- day09__Python的Socket协议介绍