poj2411--Mondriaan's Dream(状压dp+dfs)
Mondriaan's Dream
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 12315 | Accepted: 7189 |
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! 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 2 1 3 1 4 2 2 2 3 2 4 2 11 4 11 0 0
Sample Output
1 0 1 2 3 5 144 51205
1*2的长方形木块,问组成h*w的大长方形的种数。
从第 i行放一个小木块后,可能会对下一行造成影响,但最多只会影响到下一层。
【poj2411--Mondriaan's Dream(状压dp+dfs)】dp[i][j]代表第当1到i-1行铺满后,第i行为状态j的种数。状态j为每一行的二进制压缩1代表存在了木块,0代表不存在。在第i行遍历所有的j,对每一个状态进行dfs,找到可以填满的一种情况,得到下一行的状态。
#include
#include
#include
using namespace std ;
#define LL __int64
LL 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<
推荐阅读
- Floating|Floating dream
- 2019ICPC南昌|2019ICPC南昌 B.A Funny Bipartite Graph(状压dp)
- Codeforces580|Codeforces580 D. Kefa and Dishes(状压dp)
- 动态规划|动态规划 —— 状压DP (附一些位运算小知识)
- 动态规划----状压dp|牛客练习题---21873(牛牛的计算机内存【状压dp】)
- Codeforces|Codeforces Round #531 (Div. 3) F. Elongated Matrix(状压DP)
- 《Dream|《Dream Road》
- FWT|【LOJ #2340】【WC 2018】—州区划分(子集卷积+状压dp)
- DP|[BZOJ]4160: [Neerc2009]Exclusive Access 2 状压DP+Dilworth定理
- 状压dp|[WC2018]州区划分