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. PowerBI 的简单介绍

    一  切片器 给我的感觉就是groupby,就是按照某个维度进行了分组,然后显示. https://www.jianshu.com/p/2e78bf342747 二  建模 https://zhuan ...

  2. sql时间类型相关

    1.现在时间 NOW() 示例: select * from users where date<now() 2.时间相减 INTERVAL ' DAY 示例: ' DAY 3.timestamp ...

  3. C#—Nhibernate使用教程

    本篇文章,让我们一起来探索Nhibernate.首先我们去搜索Nhibernate下载地址,如下链接所示.该版本可能是最新版,我下载的4.0.4.GA.其中GA意思我没搞清楚.不过应该不重要.http ...

  4. springboot An incompatible version [1.1.32] of the APR based Apache Tomcat Native library is installed, while Tomcat requires version [1.2.14]

    1.错误 An incompatible version [1.1.32] of the APR based Apache Tomcat Native library is installed, wh ...

  5. MVC 源码系列之控制器激活(一)

    Controller的激活 上篇说到Route的使用,GetRoute的方法里面获得RouteData.然后通过一些判断,将最后的RouteData中的RouteHandler添加到context.R ...

  6. 【MM系列】SAP MM模块-移动类型全部列表

    公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP MM模块-移动类型全部列表 ...

  7. python基础数据类型补充以及编码的进阶

    一.基本数据类型的补充循环列表改变列表大小的问题#请把列表中索引为基数的元素写出l1=[1,2,3,4,5,6]for i in l1: if i%2!=0: print(i)结果:135二:基本数据 ...

  8. 执行 bower -v 时出现内部错误

    安装nodejs ,我的位置是D:\node.js_install.全局模块安装默认放在C:\Users\Administrator\AppData\Roaming\npm\node_modules里 ...

  9. 在Window平台是模拟Linux的Shell环境

    在Linux平台模拟Linux的shell环境,可以通过一个软件实现:Cygwin(点击进入官网下载好即可),如下图(选择对应的版本进行下载): 安装: 1. 双击运行下载的安装包(选择从网络安装), ...

  10. [Bzoj3262]陌上花开(CDQ分治&&树状数组||树套树)

    题目链接 题目就是赤裸裸的三维偏序,所以用CDQ+树状数组可以比较轻松的解决,但是还是树套树好想QAQ CDQ+树状数组 #include<bits/stdc++.h> using nam ...