poj 2411 Mondriaan's Dream (轮廓线DP)
题意:有一个n*m的棋盘,要求用1*2的骨牌来覆盖满它,有多少种方案?(n<12,m<12)
思路:
由于n和m都比较小,可以用轮廓线,就是维护最后边所需要的几个状态,然后进行DP。这里需要维护的状态数就是min(n,m)。即大概是一行的大小。每次放的时候,只考虑(1)以当前格子为右方,进行横放;(2)以当前格子为下方进行竖放;(3)还有就是可以不放。
3种都是不一样的,所以前面的一种状态可能可以转为后面的几种状态,只要满足了条件。条件是,横放时,当前格子不能是最左边的;竖放时,当前格子不能是最上边的。而且要放的时候,除了当前格子,另一个格子也是需要为空才行的。
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#define pii pair<int,int>
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
const int N=1e5+;
LL dp[][<<]; LL cal(int n,int m)
{
if(n<m) swap(n,m);
memset(dp, , sizeof(dp));
dp[][(<<m)-]=;
int cur=;
int h=(<<(m-));
for(int i=; i<n; i++)
{
for(int k=; k<m; k++)
{
cur^=;
memset(dp[cur], , sizeof(dp[cur]));
for(int j=; j<(<<m); j++)
{
if( j&h ) dp[cur][(j^h)<<]+=dp[cur^][j]; //最高位为1时,可以不放
if( k && !(j&) && (h&j)) dp[cur][((j&(h-))<<)|]+=dp[cur^][j]; //放横,左边为0,上面为1
if( i && !(h&j) ) dp[cur][(j<<)|]+=dp[cur^][j]; //放竖,上面为0
}
}
}
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代码
UVA一样的题:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33787
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#define pii pair<int,int>
#define INF 0x3f3f3f3f
#define LL long long
using namespace std;
const int N=;
LL dp[][<<N]; LL cal(int n,int m)
{
if(n<m) swap(n,m);
memset(dp, , sizeof(dp));
dp[][(<<m)-]=;
int cur=, h=(<<(m-));
for(int i=; i<n; i++)
{
for(int k=; k<m; k++)
{
cur^=;
for(int j=; j<(<<m); j++) dp[cur][j]=;
for(int j=; j<(<<m); j++)
{
if( j&h ) dp[cur][(j^h)<<]+=dp[cur^][j]; //最高位为1时,可以不放
if( k && !(j&) && (h&j)) dp[cur][((j&(h-))<<)|]+=dp[cur^][j]; //放横,左边为0,上面为1
if( i && !(h&j) ) dp[cur][(j<<)|]+=dp[cur^][j]; //放竖,上面为0
}
}
}
return dp[cur][(<<m)-];
} int main()
{
//freopen("input.txt", "r", stdin);
int n, m;
while(~scanf("%d%d",&n,&m)) printf("%lld\n", cal(n,m));
return ;
}
AC代码
poj 2411 Mondriaan's Dream (轮廓线DP)的更多相关文章
- poj 2411 Mondriaan's Dream 轮廓线dp
题目链接: http://poj.org/problem?id=2411 题目意思: 给一个n*m的矩形区域,将1*2和2*1的小矩形填满方格,问一共有多少种填法. 解题思路: 用轮廓线可以过. 对每 ...
- 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)的棋盘,问填满它有多少 ...
随机推荐
- Servlet执行过程
servlet生命周期: Servlet对象是在第一次访问时由容器创建,并完成初始化工作. 对于用户的多次请求,都会调用service为您服务,而不会再创建新的对象. 当应用被写在或者Tomcat关闭 ...
- OnCtlColor
https://baike.baidu.com/item/OnCtlColor/4750440?fr=aladdin CTLCOLOR_BTN 按钮控件 · CTLCOLOR_DLG 对话框 · CT ...
- %02d %03d
strTemp.Format("%02d",m_unEditPosition); %02d 输出两位整数,不足两位的前面加0,比如05,06…… %03d 输出三位整数,不足两位的 ...
- Spring中JdbcTemplate的基础用法
Spring中JdbcTemplate的基础用法 1.在DAO中使用JdbcTemplate 一般都是在DAO类中使用JdbcTimplate,在XML配置文件中配置好后,可以在DAO中注入即可. 在 ...
- crontab计划任务监控nginx服务器
#!/bin/bash ps axu |grep 'nginx' |grep -v 'grep' &>/dev/null ] then echo "准备重启nginx....& ...
- Flutter实战视频-移动电商-37.路由_Fluro引入和商品详细页建立
37.路由_Fluro引入和商品详细页建立 https://github.com/theyakka/fluro pages/details_page.dart新建页面 使用路由 先添加路由插件的引用 ...
- 利用StringBuffer来替换内容
package com.test.java; public class StringBufferTest { public static void main(String[] args) { Stri ...
- Ogre的mesh和skeleton文件数据格式分析
转载自: http://www.cnblogs.com/topicofkevin/archive/2012/03/05/2380808.html 首先看一下skeleton文件,skeleton文件描 ...
- 实现easyui combobox中textField字段的拼接
开发过程中遇到这样的一个需求: 从后台得到的两个字段aa.bb拼接为一个字段aabb显示在easyui combobx的下拉选项中. 实现方法: 利用formatter属性定义如何呈现行: 页面代码: ...
- Debug和Release版本区别
Debug和Release版本区别 众所周知,我们尽心iOS开发,在Xocde调试程序时,分为两种方式Debug和Release,在Target的Setting中相信大家应该能看到很多选项分别为Deb ...