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 ...
随机推荐
- 7.20实习培训日志-Java基础程序设计结构
Java基础程序设计结构 在 Math 类中,为了达到最快的性能,所有的方法都使用计算机浮点单元中的例程,如果得到一个完全可预测的结果比运行速度更重要的话,那么就应该使用StrictMath类,它使用 ...
- ACM-ICPC2018焦作网络赛 Mathematical Curse(dp)
Mathematical Curse 22.25% 1000ms 65536K A prince of the Science Continent was imprisoned in a cast ...
- PHP面向对象--接口实例
我们设计一个在线销售系统,用户部分设计如下: 将用户分为,NormalUser, VipUser, InnerUser三种. 要求根据用户的不同折扣计算用户购买产品的价格. 并要求为以后扩展和维护预留 ...
- [Leetcode]847. Shortest Path Visiting All Nodes(BFS|DP)
题解 题意 给出一个无向图,求遍历所有点的最小花费 分析 1.BFS,设置dis[status][k]表示遍历的点数状态为status,当前遍历到k的最小花费,一次BFS即可 2.使用DP 代码 // ...
- 51nod1412(dp)
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1412 代码: #include <bits/stdc+ ...
- solidity 学习笔记(3) 函数修饰符/继承
修饰符: 函数修饰符有 constant view pure 其中 constant和view的功能是一样的 不会消耗gas 也就是说不会做任何存储 constant在5.0以后的版本中被废弃 ...
- LDAP理论知识
整理改编自: https://www.cnblogs.com/yjd_hycf_space/p/7994597.html http://blog.51cto.com/407711169/1439623 ...
- centOS-7.5上安装redis-5.0.0
- Count the string (KMP+DP)
题目链接 #include <bits/stdc++.h> using namespace std; typedef long long ll; inline int read() { , ...
- JS高级学习历程-3
JS-作用域链及作用 [作用域链] 1 什么事作用域链 一个变量,在当前环境可以使用,当前环境的内部环境也可以使用,内部的深层环境...也可以使用,变量在不同环境都可以使用的现象想成了一个链条,称为“ ...