博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ_2411_Mondriaan's Dream_状态压缩dp
阅读量:7097 次
发布时间:2019-06-28

本文共 2170 字,大约阅读时间需要 7 分钟。

Mondriaan's Dream
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 15407   Accepted: 8889

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!

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 大意:h,w分别为一个矩形的长和宽(h,m<=11),问用1*2的小矩形(可横竖摆放),问一共有多少种方法。 状态压缩,竖着摆放的小矩形占据该行的该位置和上一行对应位置,0表示该位置不摆放(即下一行竖着摆放的小矩形占据这个位置),1表示该位置摆放(横或竖)
   dfs(l+2,now<<2|3,pre<<2|3);   上下两行横着摆放     dfs(l+1,now<<1|1,pre<<1);    当前行竖着摆放,并占据上一行对应位置     dfs(l+1,now<<1,pre<<1|1);    上一行对应位置无论如何被占据,当前行由下一行竖着摆放的矩形占据 dfs搜出所有可能的路径path[num][2];path[i][0]存第i条路的当前状态,path[i][1]存第i条路的上一行状态。 剩下的dp很常规。
#include
#include
#include
#include
#include
#include
using namespace std;#define LL long longint path[14000][2];LL dp[15][2<<11];int h,w,num;void dfs(int l,int now,int pre){ if(l>w) return; if(l==w) { path[num][0]=now; path[num++][1]=pre; return; } dfs(l+2,now<<2|3,pre<<2|3); dfs(l+1,now<<1|1,pre<<1); dfs(l+1,now<<1,pre<<1|1);}int main(){ while(scanf("%d%d",&h,&w)!=EOF&&h+w) { num=0; dfs(0,0,0); memset(dp,0,sizeof(dp)); dp[0][(1<

 

转载于:https://www.cnblogs.com/jasonlixuetao/p/5776666.html

你可能感兴趣的文章
《统一沟通-微软-实战》-6-部署-3-监控服务器
查看>>
Windows Server 2012 之NIC组合(NIC Teaming)介绍
查看>>
.NET简谈自定义事务资源管理器
查看>>
《统一沟通-微软-实战》-3-部署-Exchange 2010-4-基本配置
查看>>
云存储:简单易用是硬道理
查看>>
激情转型 三大战役重塑AMD
查看>>
CentOS6.5+puppet3.7.3 安装、配置及测试
查看>>
(转载)showModalDialog关闭子窗口刷新主窗口
查看>>
ACM HDU 1219 AC me(简单题,但是花了很长时间才AC)
查看>>
Ethernet LEDs
查看>>
row_number()over函数的使用(转)
查看>>
怎样在Delphi中屏蔽Flash控件的右键弹出菜单
查看>>
[BuildRelease]Mozilla Build Tools - Autoconf + GNU Make
查看>>
DRM-内容数据版权加密保护技术学习(上):视频文件打包实现(转)
查看>>
Html.ActionLink 几种重载方式说明及例子
查看>>
[转]spinlock 理解
查看>>
今天看腾讯在北航的演讲《1亿在线背后的技术挑战》想到的关于MD5算法。
查看>>
SQL高级---SQL Alias(别名)
查看>>
Android开发历程_5(Activity相对布局)
查看>>
OSI
查看>>