POJ 2411 Mondriaan's Dream (状压DP,骨牌覆盖,经典)
题意:
用一个2*1的骨牌来覆盖一个n*m的矩形,问有多少种方案?(1<=n,m<=11)

思路:
很经典的题目,如果n和m都是奇数,那么答案为0。同uva11270这道题。
只需要m个bit来记录状态行了,标记是否已经被覆盖到了。考虑当前格子,如果上面格子未覆盖,则必须放竖的,否则,将再也覆盖不到此格子;如果上面格子已经覆盖,而左边未覆盖,那么还可以选择放横的,或者是不放(左边若未覆盖可以由左下格子去考虑)。
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <deque>
#include <map>
#include <algorithm>
#include <vector>
#include <iostream>
#define pii pair<int,int>
#define INF 0x3f3f3f3f
#define LL long long
#define ULL unsigned long long
using namespace std;
const double PI = acos(-1.0);
const int N=;
LL dp[][<<], cur; LL cal(int n,int m)
{
if(n==m&&n%==) return ;
if(n<m) swap(n,m);
memset(dp[],,sizeof(dp[]));
dp[cur=][(<<m)-]=;
for(int i=; i<=n; i++)
{
for(int j=; j<=m; j++)
{
cur^=;
memset(dp[cur],,sizeof(dp[cur]));
int r=(<<m)-;
for(int s=; s<(<<m); s++)
{
LL v=dp[cur^][s];
if( (s&(<<m-))== ) //必须放竖
dp[cur][(s<<)+]+=v;
else
{
dp[cur][(s<<)&r]+=v; //不放
if( j> && (s&)== ) //放横
dp[cur][((s<<)+)&r]+=v;
}
}
}
}
return dp[cur][(<<m)-];
} int main()
{
freopen("input.txt","r",stdin);
int n, m;
while(scanf("%d%d",&n,&m),n+m)
printf("%lld\n",cal(n,m));
return ;
}
AC代码
POJ 2411 Mondriaan's Dream (状压DP,骨牌覆盖,经典)的更多相关文章
- 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)
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Description Squares and rectangles fascina ...
- POJ 2411 Mondriaan's Dream ——状压DP 插头DP
[题目分析] 用1*2的牌铺满n*m的格子. 刚开始用到动规想写一个n*m*2^m,写了半天才知道会有重复的情况. So Sad. 然后想到数据范围这么小,爆搜好了.于是把每一种状态对应的转移都搜了出 ...
- POJ 2411 Mondriaan'sDream(状压DP)
题目大意:一个矩阵,只能放1*2的木块,问将这个矩阵完全覆盖的不同放法有多少种. 解析:如果是横着的就定义11,如果竖着的定义为竖着的01,这样按行dp只需要考虑两件事儿,当前行&上一行,是不 ...
- [poj2411] Mondriaan's Dream (状压DP)
状压DP Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One nigh ...
- 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 Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One nig ...
- poj 2411 Mondriaan's Dream(状态压缩dP)
题目:http://poj.org/problem?id=2411 Input The input contains several test cases. Each test case is mad ...
- poj 2411 Mondriaan's Dream (轮廓线DP)
题意:有一个n*m的棋盘,要求用1*2的骨牌来覆盖满它,有多少种方案?(n<12,m<12) 思路: 由于n和m都比较小,可以用轮廓线,就是维护最后边所需要的几个状态,然后进行DP.这里需 ...
- POJ 2411 Mondriaan's Dream 插头dp
题目链接: http://poj.org/problem?id=2411 Mondriaan's Dream Time Limit: 3000MSMemory Limit: 65536K 问题描述 S ...
随机推荐
- qpython 读入数据问题: EOF error with input / raw_input
直接使用input会报错 EOF error with input / raw_input 原因是在qpy里console mode 命令行模式不是完全和pc上的命令行一致,所以input和raw_i ...
- Android Studio如何导出可供Unity使用的aar插件详解
http://www.cnblogs.com/xtqqkss/p/6387271.html 前言 项目之前使用Eclipse导出的jar文件来做与Android交互,最近因为工作需要需使用Androi ...
- AI资源
网易云课堂 http://study.163.com/topics/IBMOfflinePrograms?utm_source=baidu&utm_medium=cpc&utm_cam ...
- 为产品接入微信支付解决方案(公司&个人)
微信支付个人及公司的区别 H5支付:主要实现的效果是在非微信内网页中点击支付,拉起微信APP内的微信支付进行付款. APP支付:主要实现的效果是在APP内部点击支付,拉起微信APP内的微信支付进行付款 ...
- Spring+SpringMVC+JDBC实现登录
Spring+SpringMVC+JDBC实现登录 有一位程序员去相亲的时候,非常礼貌得说自己是一名程序员,并解释自己是做底层架构的,于是女方听到"底层"两个字,就一脸嫌弃:什么时 ...
- MySql提示:The server quit without updating PID file(…)失败之解决办法(来源网络仅供参考)
1.可能是/usr/local/mysql/data/rekfan.pid文件没有写的权限 解决方法 :给予权限,执行 “chown -R mysql:mysql /var/data” “chmod ...
- POJ-2777-CountColor(线段树,位运算)
链接:https://vjudge.net/problem/POJ-2777#author=0 题意: Chosen Problem Solving and Program design as an ...
- 关于FutureTask的探索
之前关于Java线程的时候,都是通过实现Runnable接口或者是实现Callable接口,前者交给Thread去run,后者submit到一个ExecutorService去执行. 然后知道了还有个 ...
- memcache和iptables开启11211端口
linux下安装完memcached后,netstat -ant | grep LISTEN 看到memcache用的11211端口已在监听状态,但建立php文件连接测试发现没有输出结果,iptabl ...
- mysql explain 的extra中using index ,using where,using index condition,using index & using where理解
using index :查找使用了索引,查询结果覆盖了索引 using where:查找使用了索引,不需要回表去查询所需的数据,查询结果是索引的一部分 using index condition:查 ...