题目:http://poj.org/problem?id=2411

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.

题意:一个矩阵,只能放1*2的木块,问将这个矩阵完全覆盖的不同放法有多少种。

思路:一道很经典的状态dp,但是还是很难想,横着放定义为11,竖着放定义为01.

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;
__int64 d[][<<], f[<<];//用———int64,因为有可能数很大
int h, w, full; bool ok(int x) //判断一行里是否出现连续奇数个1,第一行的话不允许
{
int sum = ;
while(x>)
{
if((x&)==)
sum++;
else
{
if((sum&)==)
return false;
sum = ;
}
x = (x>>);
}
if((sum&)==)
return false;
return true;
}
bool check(int x1, int x2)
{
int xx = (<<w)-;
if((x1|x2)==xx&&f[x1&x2])//去掉竖着00和竖着单独11的情况,一定不要忘了单独11的情况
return true;
return false;
}
int main()
{
int i, j, k;
memset(f, , sizeof(f));
full = (<<); for(i = ; i < full; i++)
if(ok(i))
f[i] = ; //记录连续的奇数个1
while(~scanf("%d%d", &h, &w))
{
if(h==&&w==)
break;
full = (<<w);
memset(d, , sizeof(d));
for(i = ; i < full; i++)
if(f[i])
d[][i] = ; for(k = ; k < h; k++)
for(i = ; i < full; i++)
for(j = ; j < full; j++)
{
if(check(i, j))
d[k][i] += d[k-][j];
}
printf("%I64d\n", d[h-][full-]); //最后一行,而且满1
}
return ;
}

poj 2411 Mondriaan's Dream(状态压缩dP)的更多相关文章

  1. poj 2411 Mondriaan's Dream_状态压缩dp

    题意:给我们1*2的骨牌,问我们一个n*m的棋盘有多少种放满的方案. 思路: 状态压缩不懂看,http://blog.csdn.net/neng18/article/details/18425765 ...

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

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

  3. Poj 2411 Mondriaan's Dream(状压DP)

    Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Description Squares and rectangles fascina ...

  4. 【poj2411】Mondriaan's Dream 状态压缩dp

    AC传送门:http://vjudge.net/problem/POJ-2411 [题目大意] 有一个W行H列的广场,需要用1*2小砖铺盖,小砖之间互相不能重叠,问有多少种不同的铺法? [题解] 对于 ...

  5. POJ - 2411 Mondriaan's Dream(轮廓线dp)

    Mondriaan's Dream Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One nig ...

  6. POJ2411 - Mondriaan's Dream(状态压缩DP)

    题目大意 给定一个N*M大小的地板,要求你用1*2大小的砖块把地板铺满,问你有多少种方案? 题解 刚开始时看的是挑战程序设计竞赛上的关于铺砖块问题的讲解,研究一两天楞是没明白它代码是怎么写的,智商捉急 ...

  7. poj 2411 Mondriaan's Dream (轮廓线DP)

    题意:有一个n*m的棋盘,要求用1*2的骨牌来覆盖满它,有多少种方案?(n<12,m<12) 思路: 由于n和m都比较小,可以用轮廓线,就是维护最后边所需要的几个状态,然后进行DP.这里需 ...

  8. POJ 2411 Mondriaan's Dream ——状压DP 插头DP

    [题目分析] 用1*2的牌铺满n*m的格子. 刚开始用到动规想写一个n*m*2^m,写了半天才知道会有重复的情况. So Sad. 然后想到数据范围这么小,爆搜好了.于是把每一种状态对应的转移都搜了出 ...

  9. Poj 2411 Mondriaan's Dream(压缩矩阵DP)

    一.Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, ...

随机推荐

  1. bnuoj 33647 Angry Grammar Nazi(字符串)

    http://www.bnuoj.com/bnuoj/problem_show.php?pid=33647 [题意]:字符串匹配,暴力配就行了 [题解]:截出单词,然后进行匹配就行了 [code]: ...

  2. 【转】如何设置Android软键盘的默认不弹出?

    在开发Anroid的时候,当你打开一个界面的时候,屏幕的焦点会自动停留在第一个EditText中,Android的软键盘默认会自动弹出,用户第一眼连界面都没有看清楚,软键盘就弹出来了,这就影响到了用户 ...

  3. 3044 矩形面积求并 - Wikioi

    题目描述 Description 输入n个矩形,求他们总共占地面积(也就是求一下面积的并) 输入描述 Input Description 可能有多组数据,读到n=0为止(不超过15组) 每组数据第一行 ...

  4. MongoDB { code: 18, ok: 0.0, errmsg: "auth fails" } 原因

    MongoDB出现 { code: 18, ok: 0.0, errmsg: "auth fails" }  错误的原因: 1.账号密码错误 2.账号不属于该数据库

  5. PAT-乙级-1050. 螺旋矩阵(25)

    1050. 螺旋矩阵(25) 时间限制 150 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 CHEN, Yue 本题要求将给定的N个正整数按非递增的 ...

  6. 【转】System.DateTime.Now.ToString()的一些用法

    C#中的日期处理函数     //2007年4月24日     this.TextBox6.Text = System.DateTime.Now.ToString("D");    ...

  7. NGINX的奇淫技巧 —— 6. IF实现数学比较功能 (1)

    NGINX的奇淫技巧 —— 6. IF实现数学比较功能 (1) ARGUS 1月13日 发布 推荐 0 推荐 收藏 3 收藏,839 浏览 nginx的if支持=.!= 逻辑比较, 但不支持if中 & ...

  8. Chp12: Testing

    What the Interviewer is Looking for: Big Picture Understanding Knowing How the Pieces Fit Together O ...

  9. linux下cat命令详解

    简略版: cat主要有三大功能:1.一次显示整个文件.$ cat filename2.从键盘创建一个文件.$ cat > filename     只能创建新文件,不能编辑已有文件.3.将几个文 ...

  10. C Primer Plus 第3章 数据和C 编程练习

    1. /* 整数上溢 */ #include <stdio.h> int main(void) { ; unsigned ; /* 无符号整数j像一个汽车里程指示表(形容的太好了,可参考& ...