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的更多相关文章

  1. [poj P2411] Mondriaan's Dream

    [poj P2411] Mondriaan's Dream Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 18023   A ...

  2. PKU 2411 Mondriaan's Dream 状态DP

    以前做过这题,今天又写了一次,突然发现写了一个好漂亮的DFS……(是不是太自恋了 - -#) 代码: #include <cstdio> #include <cstring> ...

  3. POJ 题目2411 Mondriaan's Dream(状压DP)

    Mondriaan's Dream Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 13519   Accepted: 787 ...

  4. HDU 1400 (POJ 2411 ZOJ 1100)Mondriaan's Dream(DP + 状态压缩)

    Mondriaan's Dream Problem Description Squares and rectangles fascinated the famous Dutch painter Pie ...

  5. POJ2411 Mondriaan's Dream(状态压缩)

    Mondriaan's Dream Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 15295   Accepted: 882 ...

  6. POJ 2411 Mondriaan's Dream -- 状压DP

    题目:Mondriaan's Dream 链接:http://poj.org/problem?id=2411 题意:用 1*2 的瓷砖去填 n*m 的地板,问有多少种填法. 思路: 很久很久以前便做过 ...

  7. POJ2411 铺地砖 Mondriaan's Dream

    Mondriaan's Dream Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 15962   Accepted: 923 ...

  8. POJ 2411 Mondriaan's Dream 插头dp

    题目链接: http://poj.org/problem?id=2411 Mondriaan's Dream Time Limit: 3000MSMemory Limit: 65536K 问题描述 S ...

  9. 【POJ2411】Mondriaan's Dream(轮廓线DP)

    [POJ2411]Mondriaan's Dream(轮廓线DP) 题面 Vjudge 题解 这题我会大力状压!!! 时间复杂度大概是\(O(2^{2n}n^2)\),设\(f[i][S]\)表示当前 ...

随机推荐

  1. 阶段1 语言基础+高级_1-3-Java语言高级_1-常用API_1_第5节 String类_4_字符串的比较相关方法

    字符串的常用方法 equals是对内容的比较 直接用字符串.equals 小写的h和大写的H肯定是不一样的 推荐和不推荐的写法 运行程序不会报任何的错误 如果把str5设置为null.那么推荐的写法返 ...

  2. spring boot 启动之后404

    <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring- ...

  3. 【EWM系列】SAP EWM WCU和Non-SAP系统接口

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP EWM WCU和Non-SA ...

  4. 【ABAP系列】SAP ABAP ALV设置背景图片

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP abap ALV设置背景图片 ...

  5. 002/区块链核心概念与原理详解(Mooc)

    1.课程介绍 (一).区块链前世今生 密码朋克--神秘组织(邮件组) 2.区块链核心概念与原理 (一)比特币是数字货币 为什么叫区块链? 因为比特币系统里面的数据是一个个的区块来存储,并且通过hash ...

  6. java静态代码块,构造方法,初始化块的执行顺序

    代码Parent和Sub进行讲解 public class Parent { private static final String name; public Parent() { System.ou ...

  7. MySQL-第十三篇使用ResultSetMetaData分析结果集

    1.Result里面包含了一个getMetaData()方法,该方法返回该ResultSet对应的ResultSetMetaData对象. 2.ResultSetMetaData包含的方法: 1> ...

  8. 对第一个HelloWorld程序的总结:

    /* 注释的作用 :提高了代码的阅读性:调试程序的重要方法 对第一个程序的总结: 创建:创建一个以.java结尾的文件叫做源文件 编译:(javac 源文件名.java) 会生成一个或多个字节码(.c ...

  9. 在学习linux磁盘管理期间学习的逻辑卷管理笔记

    LVM(逻辑分区)的创建顺序:物理分区-物理卷-卷组-逻辑卷-挂载. 物理卷(Physical Volume,PV):就是指硬盘分区,也可以是整个硬盘或已创建的软RAID,是LVM的基本存储设备. 卷 ...

  10. CSS3制作的垂直口风琴1

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...