POJ 2411 Mondriaan's Dream
来源:互联网 发布:数组是数据结构吗 编辑:程序博客网 时间:2024/06/05 21:58
状压DP
Mondriaan's Dream
Time Limit: 3000MSMemory Limit: 65536KTotal Submissions: 9938Accepted: 5750
用0表示竖着放的木块的上半部分,单独的1表示竖着的木块的下半部分,两个连续的1表示横着放的木块.
最后一行铺满的状态就是全部为1
上下行的兼容性:
1:下面为0上面一定不能为0
2:下面为1.....如果上面为0,那么这是一个单独的1
如果上面为1,那么这应该是一个连续的1,检查下一位是否为1,及下一位的上面是否为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 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
Source
Ulm Local 2000用0表示竖着放的木块的上半部分,单独的1表示竖着的木块的下半部分,两个连续的1表示横着放的木块.
最后一行铺满的状态就是全部为1
上下行的兼容性:
1:下面为0上面一定不能为0
2:下面为1.....如果上面为0,那么这是一个单独的1
如果上面为1,那么这应该是一个连续的1,检查下一位是否为1,及下一位的上面是否为1
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
long long int dp[14][1<<14];
int r,c;
bool isfirst(int x)
{
int ans=0;
for(int i=0;i<c;i++)
if((x>>i)&1) ans++;
if(ans%2==1) return false;
for(int i=0;i<c;i++)
{
if((x>>i)&1)
{
if((x>>(i+1))&1)
i++;
else
return false;
}
}
return true;
}
void getfirstline()
{
for(int i=0;i<(1<<c);i++)
{
if(isfirst(i))
{
dp[1]=1;
/*
for(int j=0;j<c;j++)
{
printf("%d ",(i>>j)&1);
}
putchar(10);
*/
}
}
}
bool isCool(int xia,int shang)
{
for(int i=0;i<c;i++)
{
if(((xia>>i)&1)==0)
{
if(((shang>>i)&1)==0) return false;
}
else
{
if(((shang>>i)&1)==0) continue;
else
{
if(i+1>=c) return false;
if(((xia>>(i+1))&1)==1)
{
if(((shang>>(i+1))&1)==1)
i++;
else
return false;
}
else
return false;
}
}
}
return true;
}
int main()
{
while(scanf("%d%d",&r,&c)!=EOF&&r&&c)
{
memset(dp,0,sizeof(dp));
if(r<c) swap(r,c);
getfirstline();
for(int i=2;i<=r;i++)
{
for(int j=0;j<(1<<c);j++)
{
for(int k=0;k<(1<<c);k++)
{
if(isCool(j,k))
{
dp[j]+=dp[i-1][k];
}
}
}
}
printf("%I64d\n",dp[(1<<c)-1]);
}
return 0;
}
* This source code was highlighted by YcdoiT. ( style: Codeblocks )#include <cstdio>
#include <cstring>
using namespace std;
long long int dp[14][1<<14];
int r,c;
bool isfirst(int x)
{
int ans=0;
for(int i=0;i<c;i++)
if((x>>i)&1) ans++;
if(ans%2==1) return false;
for(int i=0;i<c;i++)
{
if((x>>i)&1)
{
if((x>>(i+1))&1)
i++;
else
return false;
}
}
return true;
}
void getfirstline()
{
for(int i=0;i<(1<<c);i++)
{
if(isfirst(i))
{
dp[1]
/*
for(int j=0;j<c;j++)
{
printf("%d ",(i>>j)&1);
}
putchar(10);
*/
}
}
}
bool isCool(int xia,int shang)
{
for(int i=0;i<c;i++)
{
if(((xia>>i)&1)==0)
{
if(((shang>>i)&1)==0) return false;
}
else
{
if(((shang>>i)&1)==0) continue;
else
{
if(i+1>=c) return false;
if(((xia>>(i+1))&1)==1)
{
if(((shang>>(i+1))&1)==1)
i++;
else
return false;
}
else
return false;
}
}
}
return true;
}
int main()
{
while(scanf("%d%d",&r,&c)!=EOF&&r&&c)
{
memset(dp,0,sizeof(dp));
if(r<c) swap(r,c);
getfirstline();
for(int i=2;i<=r;i++)
{
for(int j=0;j<(1<<c);j++)
{
for(int k=0;k<(1<<c);k++)
{
if(isCool(j,k))
{
dp
}
}
}
}
printf("%I64d\n",dp
}
return 0;
}
0 0
- POJ 2411 Mondriaan&#39;s Dream
- POJ 2411 Mondriaan's Dream
- poj 2411 Mondriaan's Dream
- poj 2411 Mondriaan's Dream
- poj 2411 Mondriaan's Dream
- POJ 2411 Mondriaan's Dream
- poj 2411 Mondriaan's Dream
- poj 2411 Mondriaan's Dream
- POJ 2411 Mondriaan's Dream
- poj 2411 Mondriaan's Dream
- POJ 2411: Mondriaan's Dream
- POJ 2411 Mondriaan's Dream
- poj 2411 Mondriaan's Dream
- POJ 2411 Mondriaan's Dream
- POJ 2411 Mondriaan's Dream
- POJ 2411 Mondriaan's Dream
- POJ-2411-Mondriaan's Dream
- poj 2411 Mondriaan's Dream
- ActiveReports 报表应用教程 (8)---交互式报表之动态过滤
- CSDN下载频道2014年11月4日-5日维护公告
- UESTC 1851 Kings on a Chessboard
- ActiveReports 报表应用教程 (9)---交互式报表之动态排序
- 什么是PMP
- POJ 2411 Mondriaan&#39;s Dream
- ActiveReports 报表应用教程 (10)---交互式报表之向下钻取(详细数据按需显示解决方案)
- POJ 3254 Corn Fields
- ActiveReports 报表应用教程 (11)---交互式报表之文档目录
- ThreadPoolExecutor原理及使用
- Flume1.5.0的安装、部署、简单应用(含伪分布式、与hadoop2.2.0、hbase0.96的案例
- 正则匹配 preg_match与preg_match_all 函数
- HDOJ 2444 The Accomodation of Students
- ActiveReports 报表应用教程 (12)---交互式报表之贯穿钻取
原创粉丝点击
热门IT博客
热门问题
老师的惩罚
人脸识别
我在镇武司摸鱼那些年
重生之率土为王
我在大康的咸鱼生活
盘龙之生命进化
天生仙种
凡人之先天五行
春回大明朝
姑娘不必设防,我是瞎子
深水龟有哪些
深水龟哪种龟好养
深水龟种类
黄耳龟是深水龟吗
深沟
一什么深沟
青行灯h沟深乳白
尴尬紧身裤现深沟图片
女人透明紧身内裤深沟
ntn深沟球轴承
深沟球轴承61801
深沟球轴承6201
深沟球轴承6202
深沟球轴承6205
深沟球微型轴承
深沟球轴承画法
陶瓷深沟球轴承
深沟球轴承价格
薄壁深沟球轴承
精密深沟球轴承
6000深沟球轴承
fag 深沟球轴承
fag深沟球轴承
开式深沟球轴承
深沟球轴承6304
6203深沟球轴承
koyo深沟球轴承
非标深沟球轴承
深沟球轴承型号
深沟球轴承规格
timken深沟球轴承
深沟球轴承参数
深沟球轴承型号查询
深沟球轴承型号查询尺寸表
交浅言深君子所戒下一句
总是为情所困终于越陷越深
齐鲁股权交易中心
龙藏深泉王隐林
深泽县
深泽县招工信息
石家庄到深泽县怎么坐车