POJ2411——Mondriaan's Dream

POJ 2411 Mondriaan's Dream (轮廓线DP代码详解) Mondriaan’s DreamPOJ 2411) Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 18772 Accepted: 10717 Description Squares and rectangles fascinated the famous Dutch painter Piet... 阅读详情
Mondriaan's Dream
Time Limit: 3000MS Memory Limit: 65536K
Total Submissions: 12042 Accepted: 7011

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!

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


覆盖模型,用状压dp解决

设棋盘为n, m为了高效起见,如果n > m,就交换,如果n, m都是奇数,答案一定是0(无论放多少牌,牌所占的空间是偶数的,所以最后的空间一定是偶数才能放满

dp[0][(1<<m)-1]  = 1;

dp[i][j] += dp[i - 1][k];

其中的j和k是符合条件的状态,我们通过dfs预处理出来(把上一行和这一行的状态和在一起看做一个状态)


放置方案有3种,竖放,横放,不放(0)   如果当前行当前列为0(二进制表示状态),那么当前列上一行一定是1(否则就空出2个位置来了);如果当前行当前列为1, 那么可能是竖放,则上一行当前列是0;可能是横放,则当前行下一列是1,上一行当前列是1,上一行下一列是1

为什么竖直放置要看做01呢,这样可以保证最后一行一定全部是1

                       
                                                                                                                                                               

#include <map>  
#include <set>  
#include <list>  
#include <stack>  
#include <vector>  
#include <queue>  
#include <cmath>  
#include <cstdio>  
#include <cstring>  
#include <iostream>  
#include <algorithm>  

using namespace std;

__int64 dp[12][2100];

struct node
{
    int cur, last;
}s[14000];

int n, m, res;

void dfs(int l, int cur, int last)
{
    if (l > m)
    {
        return ;
    }
    if (l == m)
    {
        s[res].cur = cur;
        s[res++].last = last;
        return;
    }
    dfs(l + 2, (cur << 2) | 3, (last << 2) | 3);
    dfs(l + 1, (cur << 1) | 1, last << 1);
    dfs(l + 1, (cur << 1), (last << 1) | 1);
}

int main()
{
    while (~scanf("%d%d", &n, &m))
    {
        if (!m && !n)
        {
            break;
        }
        if( (m & 1) && ( n & 1) )
        {
            printf("0\n");
            continue;
        }
        if (n < m)
        {
            m ^= n;
            n ^= m;
            m ^= n;
        }
        res = 0;
        dfs(0, 0, 0);
        memset (dp, 0, sizeof(dp) );
        dp[0][(1 << m) - 1] = 1;//作为初始化,第0行只能横放,因为不能影响下面;
        for (int i = 1; i <= n; ++i)
        {
            for (int j = 0; j < res; ++j)
            {
                dp[i][s[j].cur] += dp[i - 1][s[j].last];
            }
        }
        printf("%I64d\n", dp[n][(1 << m) - 1]);
    }
}


STATA做ARIMA预测翻车?从残差检验`wntestq`到样本外预测,这份避坑指南请收好 本文详细解析了STATA中ARIMA模型从残差检验到样本外预测的完整流程,特别针对`wntestq`检验、滚动预测法等常见陷阱提供解决方案。通过实战案例和代码示例,帮助研究者避免模型诊断中的典型错误,提升时间序列预测的准确性。 阅读详情

相关推荐

【Linux 驱动开发】STM32MP1 LCD 显示系统完整实践指南

STM32MP1 LCD显示系统实践指南 本文全面介绍STM32MP1平台实现MIPI DSI LCD显示的完整流程,涵盖硬件连接、设备树配置、显示原理和驱动实现。主要内容包括: 硬件连接:详细说明MIPI DSI差分对、背光PWM、复位/供电管脚的连接方式 设备树配置: PWM背光控制节点设置 LTDC与DSI端口映射关系 Panel节点参数定义 显示基础:讲解LCD/OLED显示原理、常见接口类型(RGB/LVDS/MIPI/HDMI)及信号时序 驱动实现。

猫猫的小茶馆 466

POJ 2411 Mondriaan's Dream 解题报告

POJ 2411 Mondriaan's Dream 解题报告2 与1不同的是,没用dfs,纯dp 思路是: 用0表示没放,1表示放了。横放则左右两格都是1,竖放则上格是0,下格是1。 这种记录state的方法决定了:如果上下两行的state是确定的,那么放法唯一。 Fun(state,n)表示n这行的状态是state的时候有多少种放法。 那么我们要求的就是Fun(2^m...

deng530557273的博客 282

倍福--RS232自由口实现

RS232/485通信协议是在现场中常用到的,比如触摸屏、温控模块等设备控控制器做通信,会常用到此类协议,本文介绍RS232/485自由口通信的实现,并用PC调试助手进行测试。 目 录 软硬件版本 3 1.1. 倍福Beckhoff 3 1.1.1. 控制器硬件 3 1.1.2. 控制器软件 3 硬件连接 3 2.1. PC COM介绍 3 2.2. RS232/RS485连接 3 3.2.1. N030…………. 4 3.2.2. N031…………. 4 2.3. 实际线路连接 5 PLC程序 7 3

weixin_41883890的博客 3258

POJ 2411 Mondriaan's Dream // 状压dp

POJ 2411 Mondriaan's Dream // 状压dp http://poj.org/problem?id=2411 突然觉得这题有丶意思,拿来写写看。(是个典型例题,用2*1砖头铺满矩形的方案数) 将一列压缩成一个二进制,就是一个状态,总共2^w*h个状态,直接dp+dfs。时间复杂度O(2^w*h)。 转移的时候,已知前一行满,将当前列填满,这样转移就行了。 ...

Rshs 311

poj2411 Mondriaan's Dream

poj2411 Mondriaan’s Dream 题 意:有一个n*m的矩阵,用1 乘 2的小矩阵去填充,完全填充,问有多少种方案。 如图展示了2乘2的矩阵的填冲的方法 数据范围: 1&lt;=w&lt;=11 1&lt;=h&lt;=11 思 路:状压dp思路,数值一般不超过16。如果小矩阵横着放,则用两个连续的1,1来表示。如果竖着放则上面用0,下面用1来表示。这样小矩阵...

子灬丶逾 462

POJ 2411: Mondriaan's Dream

POJ 2411: Mondriaan's Dream 题目链接:http://poj.org/problem?id=2411 题目大意:在$h \times w$($1 \leqslant h,w \leqslant 11$)的网格中放满$1 \times 2$的木条,问有几种放置方案。 状压dp 定义横向放置的木条为$11$(横向),纵向放置的木条为$_1^0$(纵向). 这样检查转...

weixin_33708432的博客 122

【状压DPPOJ 2411 Mondriaan's Dream

POJ 2411 Mondriaan's Dream 题意:给一个n*m大的区域,问用1*2的矩形块填充,能够刚好填满的填充方式有多少? FEELING:真的吹爆神犇!!www,这个方法也太巧妙了叭qaq!!!! 大神思路蒟蒻理解: dp[i][s]: 第 i 行状态为s的种类数(保证前i - 1行是全部覆盖的) 我们用01表示(i , j)格子有没有被覆盖,那么每一行都会有一个01串...

L_X_ 208

poj 2411 Mondriaan's Dream 轮廓线dp

题目链接: http://poj.org/problem?id=2411 题目意思: 给一个n*m的矩形区域,将1*2和2*1的小矩形填满方格,问一共有多少种填法。 解题思路: 用轮廓线可以过。 对每一个格子,枚举上一个格子的状态,得到当前格子的所有状态值。 dp[cur][s]表示当前格子的轮廓线状态为s的情况下的总数 代码: #include #include #incl

cc_again的专栏 2671

poj 2411 Mondriaan's Dream

题目链接http://poj.org/problem?id=2411 Mondriaan's Dream Time Limit:3000MS Memory Limit:65536K Total Submissions:12445 Accepted:7261 Description Squares and rectangle...

weixin_30847271的博客 75

[poj P2411] Mondriaan's Dream

[poj P2411] Mondriaan's Dream Time Limit:3000MS Memory Limit:65536K Total Submissions:18023 Accepted:10327 Description Squares and rectangles fascinated the fa...

a8233821的博客 184

POJ 2411 Mondriaan's Dream

http://acm.pku.edu.cn/JudgeOnline/problem?id=2411 挺简单的一道题,由于自己很少做这类型的题目,做出来还是挺有感觉的。 每一个木块只有两种摆放方式,用0 , 1表示,0表示横放,1表示竖放,所以每一行,必须要有连续偶数个0,而且最后一行不能有1。若这一列对应的上一行有1,则这一列不能为1,但是计算的时候要把这一列看成1,若...

weixin_30906671的博客 108

POJ-2411-Mondriaan's Dream

ff

从你的全世界路过。 297

POJ2411Mondriaan's Dream

题目大意:给定一个 N*M 的棋盘,用 1*2 的木条填满有多少种不同的方式。 题解:在这里采用以行为阶段进行状压 dp。到第 i 行时,1*1 的木块分成两类,第一类是这个木块是竖着放置木条的上半部分,第二类是其他情况。对于第一种情况来说,第 i+1 行的状态只能是 0,而对于第二种情况来说,第 i+1 行没有特殊限制。因此,可以得出第一个状态转移的限制,即:上下两行之间的状态 (i,...

K1385170的博客 199

POJ2411 Mondriaan's Dream

状压DP

a free man 520

poj - 2411 Mondriaan's Dream

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,...

brucehb的专栏 261
上一篇: POJ3254——Corn Fields
下一篇: Codeforces Round #275 (Div. 2)A,B,C
tokers
博客等级 码龄12年 71粉丝 700原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值