POJ 2411 插头DP
//插头DP,算是广义路径的吧。
/*
我是这样想的,定义填数的为0,未填的为1.然后,初始自然是(0,0).我还定义了整个棋盘的状态,不知是否多此一举。
这样,把轮廓线上的格子状态记录。当(I,J)上方的格子为空,必定要填一个竖的。当左边格子为空,当前可填一个横的,也可不填。
当左边格子不为空,当前格子必为空。。。AC.
*/ #include <iostream>
#include <cstdio>
using namespace std;
int n,m;
int code[];
const int MAXL=;
const int MAXM=;
struct HASHMAP{
int hash[MAXL],next[MAXM];
__int64 f[MAXM]; int state[MAXM],alst[MAXM];
int size;
void init(){
size=;
memset(hash,-,sizeof(hash));
}
void push(int st,__int64 ans,int als){
int h=st%MAXL;
for(int i=hash[h];i!=-;i=next[i]){
if(state[i]==st){
f[i]+=ans;
return ;
}
}
f[size]=ans;
state[size]=st;
alst[size]=als;
next[size]=hash[h];
hash[h]=size++;
}
}hm[]; void decode(int st){
for(int i=;i<=m;i++){
code[i]=(st&);
st=(st>>);
}
} int encode(){
int st=; int i;
for(i=m;i>;i--){
st=(st|code[i]);
st=(st<<);
}
st=(st|code[i]);
return st;
} void dp(int i,int j,int cur){
for(int e=;e<hm[cur].size;e++){
decode(hm[cur].state[e]);
int als=hm[cur].alst[e];
if(code[j]==){
code[j]=; als--;
hm[cur^].push(encode(),hm[cur].f[e],als);
}
else{
if(code[j-]==){
code[j]=;
hm[cur^].push(encode(),hm[cur].f[e],als+);
code[j]=code[j-]=;
hm[cur^].push(encode(),hm[cur].f[e],als-);
}
else{
code[j]=;
hm[cur^].push(encode(),hm[cur].f[e],als+);
}
}
}
} int main(){
int i,j;
while(scanf("%d%d",&n,&m)!=EOF){
if(!n&&!m) break;
code[]=;
int cur=;
hm[cur].init();
hm[cur].push(,,);
for(i=;i<=n;i++)
for(j=;j<=m;j++){
hm[cur^].init();
dp(i,j,cur);
cur=cur^;
}
__int64 ans=;
for(i=;i<hm[cur].size;i++){
if(hm[cur].alst[i]==){
ans+=hm[cur].f[i];
}
}
printf("%I64d\n",ans);
}
return ;
}
POJ 2411 插头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 插头DP
[题目分析] 用1*2的牌铺满n*m的格子. 刚开始用到动规想写一个n*m*2^m,写了半天才知道会有重复的情况. So Sad. 然后想到数据范围这么小,爆搜好了.于是把每一种状态对应的转移都搜了出 ...
- POJ 2411 Mondriaan's Dream -- 状压DP
题目:Mondriaan's Dream 链接:http://poj.org/problem?id=2411 题意:用 1*2 的瓷砖去填 n*m 的地板,问有多少种填法. 思路: 很久很久以前便做过 ...
- 状压DP POJ 2411 Mondriaan'sDream
题目传送门 /* 题意:一个h*w的矩阵(1<=h,w<=11),只能放1*2的模块,问完全覆盖的不同放发有多少种? 状态压缩DP第一道:dp[i][j] 代表第i行的j状态下的种数(状态 ...
- poj 2411 Mondriaan's Dream 【dp】
题目:id=2411" target="_blank">poj 2411 Mondriaan's Dream 题意:给出一个n*m的矩阵,让你用1*2的矩阵铺满,然 ...
- Poj 2411 Mondriaan's Dream(压缩矩阵DP)
一.Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, ...
- POJ 3133 Manhattan Wiring (插头DP,轮廓线,经典)
题意:给一个n*m的矩阵,每个格子中有1个数,可能是0或2或3,出现2的格子数为2个,出现3的格子数为2个,要求将两个2相连,两个3相连,求不交叉的最短路(起终点只算0.5长,其他算1). 思路: 这 ...
- POJ 1739 Tony's Tour (插头DP,轮廓线DP)
题意:给一个n*m的矩阵,其中#是障碍格子,其他则是必走的格子,问从左下角的格子走到右下角的格子有多少种方式. 思路: 注意有可能答案是0,就是障碍格子阻挡住了去路. 插头DP有两种比较常见的表示连通 ...
- POJ - 1185 炮兵阵地 (插头dp)
题目链接 明明是道状压dp的题我为啥非要用插头dp乱搞啊 逐行枚举,设dp[i][S]为枚举到第i个格子时,状态为S的情况.S为当前行上的“插头”状态,每两个二进制位表示一个格子,设当前格子为(x,y ...
随机推荐
- 解决Sublime Text 3 的 Package Control 启动失败问题
今天在使用Sublime Text的时候,需要了这样的情况 遇到这个问题的时候 我是这样解决的 一. 首先 找到 Package Control的下载地址1 下载地址2.将下载下 ...
- Git 迁库 标签
Git迁库 (一)克隆裸库 git clone --bare https://github.com/SunArmy/Tourist.git 克隆之后进入该目录下是这样的 (二)创建新的版本库 这里我已 ...
- HttpFileCollection 类使用
public ActionResult GetForm() { HttpRequest request = System.Web.HttpContext.Curre ...
- python自动化测试学习笔记-2-列表
上次我们学习了python的基本概念,了解了python的变量及数据类型,并实战了条件判断,for/while循环,字符串输出,格式化输出的一些基本用法,接下来我们继续学习其他的一些数据类型. pyt ...
- Git 分支创建
分支策略:git上始终保持两个分支,master分支与develop分支.master分支主要用于发布时使用,而develop分支主要用于开发使用. 创建master的分支developgit che ...
- WCF开发的流程-服务端和客户端之间的通讯(内含demo讲解)
讲解技术之前,恳请博友让我说几句废话.今天是我第一在博客园发布属于自己原创的博文(如有雷同,那是绝对不可能的事,嘿嘿).之前一直是拜读各位博友的大作,受益匪浅的我在这对博友们说声谢谢,谢谢你们的共享! ...
- phpCURL抓取网页内容
参考代码1:<?php // 创建一个新cURL资源 $ch = curl_init(); // 设置URL和相应的选项 curl_setopt($ch, CURLOPT_URL, " ...
- 关于Qt 报QDomDocument: No such file or directory错误解决办法
肯定是没有找到相关的路径,这时候只需要在.pro文件中加入便好了,比如我要用到读写xml的一些头文件,则需要在.pro中加入如下代码: 就可以正常引用了.
- Zabbix自带的mysql监控模块
Zabbix自带的mysql监控模块 [root@Cagios zabbix-]# cp conf/zabbix_agentd/userparameter_mysql.conf /usr/local/ ...
- Replacing Threads with Dispatch Queues
Replacing Threads with Dispatch Queues To understand how you might replace threads with dispatch que ...