【poj2411】Mondriaan's Dream 状态压缩dp
AC传送门:http://vjudge.net/problem/POJ-2411
【题目大意】
有一个W行H列的广场,需要用1*2小砖铺盖,小砖之间互相不能重叠,问有多少种不同的铺法?
【题解】
对于每一行有w个位置,所以每一行都有0~2w-1种状态。
对于当前行的状态s,它是由前一行的状态s’转化过来的,显然,对于该行某个位置j:
如果前一行该位置为0,那么该位置可以竖放 即 0-> 1
如果前一行连续两个位置为0,那么这两个连续位置可以横放 即00-> 00
如果前一行该位置为1,显然该位置不能再放,于是应该把该位置设置为0 ,即1-> 0
/*************
poj 2411
by chty
2016.11.15
*************/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<algorithm>
using namespace std;
#define FILE "read"
#define up(i,j,n) for(int i=j;i<=n;i++)
namespace INIT{
char buf[1<<15],*fs,*ft;
inline char getc() {return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),fs==ft))?0:*fs++;}
inline int read(){
int x=0,f=1; char ch=getc();
while(!isdigit(ch)) {if(ch=='-') f=-1; ch=getc();}
while(isdigit(ch)) {x=x*10+ch-'0'; ch=getc();}
return x*f;
}
}using namespace INIT;
int n,m;
long long f[15][2500];
void dfs(int i,int s1,int s2,int next){
if(next>m) return;
if(next==m) f[i+1][s2]+=f[i][s1];
else if((s2&(1<<next))==0){
dfs(i,s1,s2|(1<<next),next+1);
if((s2&(1<<(next+1)))==0) dfs(i,s1,s2,next+2);
}
else dfs(i,s1,s2&~(1<<next),next+1);
}
int main(){
freopen(FILE".in","r",stdin);
freopen(FILE".out","w",stdout);
while(~scanf("%d%d",&n,&m)&&n&&m){
memset(f,0,sizeof(f)); f[1][0]=1;
up(i,1,n) up(j,0,(1<<m)-1) if(f[i][j]) dfs(i,j,j,0);
printf("%lld\n",f[n+1][0]);
}
return 0;
}
【poj2411】Mondriaan's Dream 状态压缩dp的更多相关文章
- POJ2411 - Mondriaan's Dream(状态压缩DP)
题目大意 给定一个N*M大小的地板,要求你用1*2大小的砖块把地板铺满,问你有多少种方案? 题解 刚开始时看的是挑战程序设计竞赛上的关于铺砖块问题的讲解,研究一两天楞是没明白它代码是怎么写的,智商捉急 ...
- poj 2411 Mondriaan's Dream(状态压缩dP)
题目:http://poj.org/problem?id=2411 Input The input contains several test cases. Each test case is mad ...
- poj2411 Mondriaan's Dream (轮廓线dp、状压dp)
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 17203 Accepted: 991 ...
- poj 2411 Mondriaan's Dream_状态压缩dp
题意:给我们1*2的骨牌,问我们一个n*m的棋盘有多少种放满的方案. 思路: 状态压缩不懂看,http://blog.csdn.net/neng18/article/details/18425765 ...
- [poj2411] Mondriaan's Dream (状压DP)
状压DP Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One nigh ...
- POJ2411 Mondriaan's Dream 题解 轮廓线DP
题目链接:http://poj.org/problem?id=2411 题目大意 给你一个 \(n \times m (1 \le n,m \le 11)\) 的矩阵,你需要用若干 \(1 \time ...
- 【POJ2411】Mondriaan's Dream(轮廓线DP)
[POJ2411]Mondriaan's Dream(轮廓线DP) 题面 Vjudge 题解 这题我会大力状压!!! 时间复杂度大概是\(O(2^{2n}n^2)\),设\(f[i][S]\)表示当前 ...
- 状态压缩dp(hdu2167,poj2411)
hdu2167 http://acm.hdu.edu.cn/showproblem.php?pid=2167 给定一个N*N的板子,里面有N*N个数字,选中一些数字,使得和最大 要求任意两个选中的数字 ...
- 状态压缩DP(大佬写的很好,转来看)
奉上大佬博客 https://blog.csdn.net/accry/article/details/6607703 动态规划本来就很抽象,状态的设定和状态的转移都不好把握,而状态压缩的动态规划解决的 ...
随机推荐
- git一键提交修改文件
git一键提交修改文件 首先安装git, 有git bash: 新建一个gitcmt文件,放置于与你的项目同级的目录里: 使用:打开git bash, 方法1. git pull\git status ...
- Scrum立会报告+燃尽图(3)选题
此作业要求参见:https://edu.cnblogs.com/campus/nenu/2018fall/homework/2193 一.小组介绍 组长:刘莹莹 组员:朱珅莹 孙韦男 祝玮琦 王玉潘 ...
- STL标准库-容器-unordered_set
技术在于交流.沟通,本文为博主原创文章转载请注明出处并保持作品的完整性 unordered_set与与unordered_map相似,这次主要介绍unordered_set unordered_set ...
- Swift 标签控制器(tabbar添加提醒和控制器)
// Override point for customization after application launch. //初始化window, 大小为设备物理大小 self.window = U ...
- HDU3861The King’s Problem
HDU3861 kosaraju缩点+最小路径覆盖 为什么是最小路径覆盖呢,我们假设有一个如下DAG图 目前我们1出发到了3处,对于3的儿子4.5.6,肯定是不能彼此到达的.所以最好的情况3只能延 ...
- python虚拟环境--virtualenv和virtualenvwrapper
python虚拟环境--virtualenv和virtualenvwrapper http://www.cnblogs.com/technologylife/p/6635631.html https: ...
- ECUST 12级 Practise
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=26399#overview 果断开小号水过 CodeForces 58A #include ...
- 【java基础】java字符串之StringBuffer和StringBuilder
[一]简述区别 package com.sxf.test.string; public class StringBufferStringBuilderTest { public static void ...
- python 中datetime 和 string 转换
dt = datetime.datetime.strptime(string_date, fmt) fmt 的格式说明如下: https://docs.python.org/2/library/dat ...
- 自定义redis session
1.思路 2.程序实现 1.用户系统类 这里模拟一个蹩脚的用户系统类(userSystem),如下: #coding=utf-8 #Redis实现用户系统 __author__ = 'beginman ...