hdu 1400 Mondriaan's Dream 状态压缩
来源:互联网 发布:淘宝飞利浦旗舰店真假 编辑:程序博客网 时间:2024/05/18 22:55
Problem 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 file 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
将1*2的方块放入n*m的格子,问有几种放法。
状态压缩,将一行压缩到一起,0表示此位置没有方块,1表示此位置已经被占用。
首先预处理一下,求出第一行可能的状态。第x位横放则为11不放则为0。
然后dfs进行搜索,第i-1行的第x位为0,则第i行的x位必为竖放1,若i-1行的x位为1,则第i行的x位有不放0,横放11两种可能。
#include <iostream>#include <cstring>using namespace std;const long long maxn=(1<<11);long long n,m,i;long long f[14][maxn];void init(long long x,long long now){ if (x==m+1) f[1][now]++; if (x>m) return; init(x+1,now<<1); init(x+2,(now<<2)|3);}void dfs(long long x,long long lst,long long nxt){ if (x==m+1){ f[i][nxt]+=f[i-1][lst]; //cerr<<x<<" "<<lst<<" "<<nxt<<endl; //cerr<<f[i][nxt]<<" "<<f[i-1][lst]<<endl; } //cerr<<i<<" "<<nxt<<" "<<f[i][nxt]<<endl; if (x>m) return; dfs(x+1,(lst<<1)|1,nxt<<1); dfs(x+1,lst<<1,(nxt<<1)|1); dfs(x+2,(lst<<2)|3,(nxt<<2)|3);}int main(){ while (cin>>n>>m) { if (m==0&&n==0) break; if (m>n) swap(m,n); memset(f,0,sizeof(f)); init(1,0); //for (int j=0;j<=(1<<m)-1;j++){//if (f[1][j]>0) cerr<<j<<endl;//cerr<<f[1][j]<<endl;} for (i=2;i<=n;i++) { dfs(1,0,0); //for (int j=0;j<=(1<<m)-1;j++){cerr<<f[i][j]<<" ";/*if (f[i][j]>0) cerr<<j<<" ";*/}cerr<<endl; } cout<<f[n][(1<<m)-1]<<endl; } return 0;}
- hdu 1400 Mondriaan's Dream 状态压缩
- poj 2411/hdu 1400 Mondriaan's Dream 状态压缩dp
- hdu 1400 Mondriaan's Dream(DP+状态压缩)
- [ACM] HDU 1400 Mondriaan's Dream (状态压缩,长2宽1长方形铺满)
- POJ 2411 && HDU 1400 Mondriaan's Dream(状态压缩DP)
- HDOJ 1400 & POJ 2411 - Mondriaan's Dream 状态压缩DP
- POJ 2411 Mondriaan's Dream 状态压缩
- POJ 2411 Mondriaan's Dream(状态压缩)
- poj2411 Mondriaan's Dream 状态压缩dp
- POJ2411:Mondriaan's Dream(状态压缩)
- poj2411 Mondriaan's Dream 状态压缩dp
- 【poj2411】Mondriaan's Dream 状态压缩dp
- POJ 2411 Mondriaan's Dream 状态压缩
- hdu 1400 Mondriaan's Dream
- hdu 1400 Mondriaan's Dream
- pku 2411 Mondriaan's Dream(状态压缩DP)
- pku 2411 Mondriaan's Dream dp 状态压缩
- dp专辑F - Mondriaan's Dream [状态压缩]
- java 作业1
- Windows下编译objective-C
- Redis源码学习之【epoll封装】
- c#好的程序员必须掌握的编码习惯
- Eclipse 编辑代码字体的设置
- hdu 1400 Mondriaan's Dream 状态压缩
- “/”应用程序中的服务器错误
- Matlab计算程序运行时间
- 在使用struts2的ModenDriven获取不到表单属性
- Oracle学习笔记——基本概念 序列
- 高校学子如何免费上网?
- [DllImport("kernel32.dll")]是什么意思??
- 小明和小强都是张老师的学生,张老师的生日是M月N日
- android 开发百度地图