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]\)表示当前 ...
随机推荐
- Week 5 - 529.Minesweeper
529.Minesweeper Let's play the minesweeper game (Wikipedia, online game)! You are given a 2D char ma ...
- Spring学习01——HelloSpring
这是一个spring入门demo: package com.su.test; public class HelloWorld { public void say(){ System.out.print ...
- 嗯,python
总觉得在这么个地方已经没有在碰blog的可能了...但是... 突然说要用python来配置环境...好歹也是这个专业的啊...还是 看看吧... 然后 百度一搜,看到一个 好的 网站,不知道 我一旦 ...
- flume 进阶
一.flume事务 put事务流程: 1.doPut:将批量数据先写入临时缓冲区putList 2.doCommit:检查Channel内存队列是否足够, (1)达到一定时间没有数据写入到putLis ...
- [AHOI2013]作业 (莫队+分块)
[AHOI2013]作业 (莫队+分块) 题面 给定了一个长度为n的数列和若干个询问,每个询问是关于数列的区间[l,r],首先你要统计该区间内大于等于a,小于等于b的数的个数,其次是所有大于等于a,小 ...
- 问题 B: 傻鸡抓大闸蟹
问题 B: 傻鸡抓大闸蟹 时间限制: 1 Sec 内存限制: 128 MB提交: 94 解决: 39[提交] [状态] [命题人:jsu_admin] 题目描述 背景又到了吃大闸蟹的季节,黄老师想 ...
- Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) - C
题目链接:http://codeforces.com/contest/831/problem/C 题意:给定k个评委,n个中间结果. 假设参赛者初始分数为x,按顺序累加这k个评委的给分后得到k个结果, ...
- touch 创建空文件或改变文件的时间戳属性
1.命令功能 touch 改变文件时间属性或创建空文件. 2.语法格式 touch [option] file touch 选项 文件名 3. 选项参数说明 参数 参数说明 -a 仅改变文件的访问 ...
- JFreeChart使用
最近项目需要做图形分析,就想到了使用JFreeChart,之前也没有使用过,就现学先用吧.本文主要记录一些主要的代码及学习使用过程. 使用JFreeChart步骤: 一.下载JFreeChart.ja ...
- 理解uboot过程中的优秀博客
To_run_away的博客 https://blog.csdn.net/qq_16777851/column/info/28098/5 加了微信好友,公众号也有文章. Camus https://c ...