poj 2411 Mondriaan's Dream 轮廓线dp
题目链接:
http://poj.org/problem?id=2411
题目意思:
给一个n*m的矩形区域,将1*2和2*1的小矩形填满方格,问一共有多少种填法。
解题思路:
用轮廓线可以过。
对每一个格子,枚举上一个格子的状态,得到当前格子的所有状态值。
dp[cur][s]表示当前格子的轮廓线状态为s的情况下的总数
代码:
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#define eps 1e-6
#define INF 0x1f1f1f1f
#define PI acos(-1.0)
#define ll long long
#define lson l,m,(rt<<1)
#define rson m+1,r,(rt<<1)|1
using namespace std; /*
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
*/
ll dp[2][1<<15]; //dp[cur][s]表示当前格子的轮廓线状态为s的情况下的总数
int n,m,cur; void update(int a,int b)
{
if(b&(1<<m)) //将前一个格子的最高位,如果是1,则置零,并更新
dp[cur][b^(1<<m)]+=dp[1-cur][a];
}
int main()
{
while(scanf("%d%d",&n,&m)&&m+n)
{
//if(m+n)
if(m>n)
swap(n,m);
memset(dp,0,sizeof(dp));
dp[0][(1<<m)-1]=1; //第一行只能横着放,把这个状态初始化为1
cur=0;
int lim=1<<m; for(int i=0;i<n;i++)
for(int j=0;j<m;j++) //对每个格子,从前面一个格子推过来
{
cur^=1;
memset(dp[cur],0,sizeof(dp[cur]));
for(int k=0;k<lim;k++) //枚举前一个格子的所有状态
{
update(k,k<<1); //不放
if(i&&!(k&(1<<(m-1))))//竖着放
update(k,(k<<1)^(1<<m)^1); //将放着的两点置1
if(j&&!(k&1))
update(k,(k<<1)^3); //横着放
}
}
printf("%lld\n",dp[cur][lim-1]);
}
return 0;
}
poj 2411 Mondriaan's Dream 轮廓线dp的更多相关文章
- POJ 2411 Mondriaan's Dream 插头dp
题目链接: http://poj.org/problem?id=2411 Mondriaan's Dream Time Limit: 3000MSMemory Limit: 65536K 问题描述 S ...
- POJ - 2411 Mondriaan's Dream(轮廓线dp)
Mondriaan's Dream Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One nig ...
- POJ 2411 Mondriaan's Dream -- 状压DP
题目:Mondriaan's Dream 链接:http://poj.org/problem?id=2411 题意:用 1*2 的瓷砖去填 n*m 的地板,问有多少种填法. 思路: 很久很久以前便做过 ...
- Poj 2411 Mondriaan's Dream(压缩矩阵DP)
一.Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, ...
- Poj 2411 Mondriaan's Dream(状压DP)
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Description Squares and rectangles fascina ...
- [poj 2411]Mondriaan's Dream (状压dp)
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 18903 Accepted: 10779 D ...
- Mondriaan's Dream 轮廓线DP 状压
Mondriaan's Dream 题目链接 Problem Description Squares and rectangles fascinated the famous Dutch painte ...
- [POJ] 2411 Mondriaan's Dream
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 18903 Accepted: 10779 D ...
- POJ2411 Mondriaan's Dream 轮廓线dp
第一道轮廓线dp,因为不会轮廓线dp我们在南京区域赛的时候没有拿到银,可见知识点的欠缺是我薄弱的环节. 题目就是要你用1*2的多米诺骨排填充一个大小n*m(n,m<=11)的棋盘,问填满它有多少 ...
随机推荐
- Sunny谈软件架构
软件架构是软件工程一个很重要的分支,随着软件规模的扩大和软件寿命的延长,软件架构也越发重要.就像建筑领域,盖一个狗窝不需要进行分析与设计,但是如果是要盖一座万人体育场或者摩天大楼,那一定会离不开设计师 ...
- hexo博客部署到github无法上传的问题
博客生成之后,按照网上别人的教程,讲项目部署到github上,修改_config.yaml中的deploy部分如下所示: deploy: type: git repository: https://g ...
- 1)③爬取网易It方面部分新闻
__author__ = 'minmin' #coding:utf-8 import re,urllib,sgmllib,os #根据当前的url获取html def getHtml(url): pa ...
- 个人收集资料整理-WebForm
[2016-03-23 20:35:53] C#实现局域网文件传输 win7系统中桌面图标显示不正常问题
- JAVA并发,CountDownLatch使用
该文章转自:http://www.itzhai.com/the-introduction-and-use-of-a-countdownlatch.html CountDownLatch 1.类介绍 一 ...
- perspective结合transform的3D效果
http://css-tricks.com/almanac/properties/p/perspective/ 链接中讲了 perspective的两种用法及比较: 1.perspective:100 ...
- android小知识之SparseArray(HaspMap替换)
最近编程时,发现一个针对HashMap<Integer, E>的一个提示: 翻译过来就是:用SparseArray<E>来代替会有更好性能.那我们就来看看源码中SparseAr ...
- linux Bash bug修复记录
- iOS面试题02-数据存储
1.如果后期需要增加数据库中的字段怎么实现,如果不使用CoreData呢? 回答:编写SQL语句来操作原来表中的字段 1>增加表字段 ALETER TABLE 表名 ADD COLUMN 字段名 ...
- bmob云 实现注册和登录的功能
向大家介绍一款我感觉非常溜的一款后端云服务bmob云 借助bmob云我们可以实现注册和登录页面的功能,下面就让我给大家演示一下借助bmob云服务实现这两个功能吧. 1. 用户是一个应用程序的核心.对 ...