PKU P2411 Mondriaan's Dream
PKU P2411 Mondriaan's Dream
题目描述:
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!
输入格式:
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.
输出格式:
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.
样例输入:
1 2
1 3
1 4
2 2
2 3
2 4
2 11
4 11
0 0
样例输出:
1
0
1
2
3
5
144
51205
提示:
1<=h,w<=11
时间限制:1000ms
空间限制:256MByte
来源:PKU
这道题本来几个月前就应该做掉的,可是自己那时候太弱了,只有现在重新刷一下了。。。
结果自己写的方法和网上的题解感觉有些不一样,我是用已知的一行去推算下一行的情况;
注意(除第一行):如果一行中有1,这个1可能代表这两种情况,一种是横着放,一种是上面一排竖下来的(那么上面一排的这个位置肯定是0),所以转移的时候要注意下下;
记住,0永远只代表着从这行竖着向下放的方块!!!(前几个月这个一直没想清楚,还想用三进制的做,真是NAIVE)
#include<bits/stdc++.h>
#define ll long long
using namespace std; ll n,m,f[][<<];
ll maxn; ll find(ll val)
{
ll t = ;
for(ll i=;i<m;i++)
{
ll ce = << i;
if(val & ce) t++;
else
{
if(t & ) return ;
t = ;
}
}
return ;
} ll check(ll now , ll down)
{
ll t = ;
for(ll i=;i<m;i++)
{
ll ce = << i;
if(down & ce)
{
if(now & ce)
t++;
else
{
if(t & ) return ;
t = ;
}
}
else
{
if(!(now & ce)) return ;
if(t & ) return ;
t = ;
}
}
if(t & ) return ;
return ;
} int main(){
while(~scanf("%lld%d",&n,&m))
{
if(!n && !m) return ;
if(n * m & )
{
cout<<<<endl;
continue;
}
memset(f,,sizeof(f));
maxn = << m;
for(ll i=;i<maxn;i++)
if(find(i))
f[][i] = ;
for(ll i=;i<n;i++)
for(ll j=;j<maxn;j++)
{
if(f[i][j])
for(ll k=;k<maxn;k++)
{
if(check(j , k))
f[i + ][k] += f[i][j];
}
}
printf("%lld\n",f[n][maxn-]);
}
}
然后这个代码刚好跑过去,吓死我啦。
可是我有想了想,总觉得我这个代码还可以优化。
如果是从这一行推下一行的话,那么第一行为什么还要重新推一次呢?
直接从第〇行开始不就好了吗???
还是NAIVE 啊 啊啊!
于是我把我的代码删了一部分,修改一点点,真的的就一点点。。。
#include<bits/stdc++.h>
#define ll long long
using namespace std; ll n,m,f[][<<];
ll maxn; ll check(ll now , ll down)
{
ll t = ;
for(ll i=;i<m;i++)
{
ll ce = << i;
if(down & ce)
{
if(now & ce)
t++;
else
{
if(t & ) return ;
t = ;
}
}
else
{
if(!(now & ce)) return ;
if(t & ) return ;
t = ;
}
}
if(t & ) return ;
return ;
} int main(){
while(~scanf("%lld%d",&n,&m))
{
if(!n && !m) return ;
if(n * m & )
{
cout<<<<endl;
continue;
}
memset(f,,sizeof(f));
maxn = << m;
f[][maxn-] = ;
for(ll i=;i<n;i++)
for(ll j=;j<maxn;j++)
{
if(f[i][j])
for(ll k=;k<maxn;k++)
{
if(check(j , k))
f[i + ][k] += f[i][j];
}
}
printf("%lld\n",f[n][maxn-]);
}
}
结果却。。。
还是NAIVE啊!!!
PKU P2411 Mondriaan's Dream的更多相关文章
- [poj P2411] Mondriaan's Dream
[poj P2411] Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 18023 A ...
- PKU 2411 Mondriaan's Dream 状态DP
以前做过这题,今天又写了一次,突然发现写了一个好漂亮的DFS……(是不是太自恋了 - -#) 代码: #include <cstdio> #include <cstring> ...
- POJ 题目2411 Mondriaan's Dream(状压DP)
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 13519 Accepted: 787 ...
- HDU 1400 (POJ 2411 ZOJ 1100)Mondriaan's Dream(DP + 状态压缩)
Mondriaan's Dream Problem Description Squares and rectangles fascinated the famous Dutch painter Pie ...
- POJ2411 Mondriaan's Dream(状态压缩)
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 15295 Accepted: 882 ...
- POJ 2411 Mondriaan's Dream -- 状压DP
题目:Mondriaan's Dream 链接:http://poj.org/problem?id=2411 题意:用 1*2 的瓷砖去填 n*m 的地板,问有多少种填法. 思路: 很久很久以前便做过 ...
- POJ2411 铺地砖 Mondriaan's Dream
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 15962 Accepted: 923 ...
- POJ 2411 Mondriaan's Dream 插头dp
题目链接: http://poj.org/problem?id=2411 Mondriaan's Dream Time Limit: 3000MSMemory Limit: 65536K 问题描述 S ...
- 【POJ2411】Mondriaan's Dream(轮廓线DP)
[POJ2411]Mondriaan's Dream(轮廓线DP) 题面 Vjudge 题解 这题我会大力状压!!! 时间复杂度大概是\(O(2^{2n}n^2)\),设\(f[i][S]\)表示当前 ...
随机推荐
- SpringBoot系列:一、SpringBoot搭建
打开IDEA,新建一个spring工程,然后无脑下一步就行. 新建完成后的目录结构 java文件夹下是java源码 resources下是配置文件 test下是测试文件 添加web模块支持,在pom. ...
- loc() iloc() at() iat()函数
1 四个函数都是用于dataframe的定位 []用于直接定位. loc()函数是用真实索引,iloc()函数是用索引序号. loc()函数切片是左闭右闭,iloc()函数切片是左闭右开. at(), ...
- c语言秋季作业1
1:你对软件工程专业或者计算机科学与技术专业了解是怎样? answer:据我上网了解软件工程是一门研究用工程化方法构建和维护有效的.实用的和高质量的软件的学科.它涉及程序设计语言.数据库.软件开发工具 ...
- C89标准和C99标准C11标准的区别
转载 C89标准和C99标准C11标准的区别 C99对C89的改变 1.增加restrict指针 C99中增加了公适用于指针的restrict类型修饰符,它是初始访问指针所指对象的惟一途径,因此只有借 ...
- HDU 6603 Azshara's deep sea(凸包+区间DP)
由于题目要求,首先维护出一个凸包,然后在凸包上寻找点对关系,用rel[i][j]表示i点和j点之间是否可以连线,又由于维护出来的凸包上的点的个数不多,可以直接枚举点对并枚举所有圆,判断两点直线和圆是否 ...
- VUE组件嵌套
vue中组件嵌套烦分为两种,分别是全局注册组件和局部注册组件 基本步骤: 1.在components 下创建一个新的.vue结尾的文件,文件首字母最好是大写,基于规范复制代码 2.分别写出结构层< ...
- Nginx针对前端静态资源的缓存处理
当用户上报一个线上的bug后,开发者修改前端代码的bug上新后,用户反映问题依旧存在的问题...这种情况是不是曾经遇到过,这个问题跟浏览器的缓存机制有很大关系(强制缓存和协商缓存,这里我就不介绍具体的 ...
- 用URLGather来管理和保存你的页面
下载链接:http://url-gather.software.informer.com/download/#downloading 安装的过程简单,这里不一一叙述. 安装成功后,找到软件安装的路径, ...
- Solr的学习使用之(七)Solr高级查询facet、facet.pivot简介
以下转载自:http://hongweiyi.com/2013/03/apache-solr-facet-introduction/ 1.什么是Faceted Search Facet['fæsɪt] ...
- Java 遇到的困难
(1)需求:xml 转 json 依赖的包:commons-beanutils-1.8.3.jarcommons-collections-3.2.1.jarcommons-lang-2.6.jarco ...