poj2411--Mondriaan's Dream(状压dp+dfs)
来源:互联网 发布:java一年工作经验 编辑:程序博客网 时间:2024/05/22 14:54
Mondriaan's Dream
Time Limit: 3000MS Memory Limit: 65536KTotal Submissions: 12315 Accepted: 7189
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
1*2的长方形木块,问组成h*w的大长方形的种数。
从第 i行放一个小木块后,可能会对下一行造成影响,但最多只会影响到下一层。
dp[i][j]代表第当1到i-1行铺满后,第i行为状态j的种数。状态j为每一行的二进制压缩1代表存在了木块,0代表不存在。在第i行遍历所有的j,对每一个状态进行dfs,找到可以填满的一种情况,得到下一行的状态。
#include <cstdio>#include <cstring>#include <algorithm>using namespace std ;#define LL __int64LL dp[15][2100] ;int h , w ;void dfs(int low_i,int low_j,int k1,int k2,int i){ if( i == w ) { dp[low_i+1][k2] += dp[low_i][low_j] ; return ; } if( (k1 & (1<<i)) ) { dfs(low_i,low_j,k1,k2,i+1) ; return ; } dfs(low_i,low_j,k1|(1<<i),k2|(1<<i),i+1) ; if( i+1 < w && (k1&(1<<(i+1))) == 0 ) dfs(low_i,low_j,(k1|(1<<i))|( 1<<(i+1) ),k2,i+2) ; return ;}int main(){ int m , i , j ; while( scanf("%d %d", &h, &w) != EOF ) { if( h == 0 && w == 0 ) break ; memset(dp,0,sizeof(dp)) ; dp[1][0] = 1 ; m = 1 << w ; for(i = 1 ; i <= h ; i++) { for(j = 0 ; j < m ; j++) { dfs(i,j,j,0,0); } } printf("%I64d\n", dp[h+1][0]) ; } return 0;}
0 0
- poj2411--Mondriaan's Dream(状压dp+dfs)
- poj2411 mondriaan's dream 状压dp
- 状压dp Mondriaan's Dream poj2411
- poj2411 Mondriaan's Dream 状压dp
- [POJ2411] Mondriaan's Dream 状压dp
- poj2411 Mondriaan's Dream--状压dp
- POJ2411:Mondriaan's Dream(状压dp)
- POJ2411 Mondriaan's Dream 【状压dp】
- poj2411 Mondriaan's Dream(状压dp)
- poj2411 Mondriaan's Dream(状压dp)
- 【状压DP】Mondriaan's Dream POJ2411 - 基础状压
- poj2411 Mondriaan's Dream 状态压缩dp
- poj2411 Mondriaan's Dream 状态压缩dp
- poj2411 Mondriaan's Dream 插头dp做法
- POJ2411 Mondriaan's Dream(压缩DP)
- POJ2411-Mondriaan's Dream-状态dp
- 【poj2411】Mondriaan's Dream 状态压缩dp
- poj2411 Mondriaan's Dream【插头dp】
- Mongodb亿级数据量的性能测试
- UIScrollView 实践经验
- Oracle客户端工具
- OC语言(一)
- Android_关于隐藏标题栏的问题
- poj2411--Mondriaan's Dream(状压dp+dfs)
- onunload-javascript
- WEB测试总结
- django extjs5 交互例子
- 动态规划-二维背包(1)
- Socket通信简单例子
- 视力减退,3招改善你的”马虎眼“
- plsql developer工具常用设置
- poker网络 -2