//插头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的更多相关文章

  1. POJ 2411 Mondriaan's Dream 插头dp

    题目链接: http://poj.org/problem?id=2411 Mondriaan's Dream Time Limit: 3000MSMemory Limit: 65536K 问题描述 S ...

  2. POJ 2411 Mondriaan's Dream ——状压DP 插头DP

    [题目分析] 用1*2的牌铺满n*m的格子. 刚开始用到动规想写一个n*m*2^m,写了半天才知道会有重复的情况. So Sad. 然后想到数据范围这么小,爆搜好了.于是把每一种状态对应的转移都搜了出 ...

  3. POJ 2411 Mondriaan's Dream -- 状压DP

    题目:Mondriaan's Dream 链接:http://poj.org/problem?id=2411 题意:用 1*2 的瓷砖去填 n*m 的地板,问有多少种填法. 思路: 很久很久以前便做过 ...

  4. 状压DP POJ 2411 Mondriaan'sDream

    题目传送门 /* 题意:一个h*w的矩阵(1<=h,w<=11),只能放1*2的模块,问完全覆盖的不同放发有多少种? 状态压缩DP第一道:dp[i][j] 代表第i行的j状态下的种数(状态 ...

  5. poj 2411 Mondriaan&#39;s Dream 【dp】

    题目:id=2411" target="_blank">poj 2411 Mondriaan's Dream 题意:给出一个n*m的矩阵,让你用1*2的矩阵铺满,然 ...

  6. Poj 2411 Mondriaan's Dream(压缩矩阵DP)

    一.Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, ...

  7. POJ 3133 Manhattan Wiring (插头DP,轮廓线,经典)

    题意:给一个n*m的矩阵,每个格子中有1个数,可能是0或2或3,出现2的格子数为2个,出现3的格子数为2个,要求将两个2相连,两个3相连,求不交叉的最短路(起终点只算0.5长,其他算1). 思路: 这 ...

  8. POJ 1739 Tony's Tour (插头DP,轮廓线DP)

    题意:给一个n*m的矩阵,其中#是障碍格子,其他则是必走的格子,问从左下角的格子走到右下角的格子有多少种方式. 思路: 注意有可能答案是0,就是障碍格子阻挡住了去路. 插头DP有两种比较常见的表示连通 ...

  9. POJ - 1185 炮兵阵地 (插头dp)

    题目链接 明明是道状压dp的题我为啥非要用插头dp乱搞啊 逐行枚举,设dp[i][S]为枚举到第i个格子时,状态为S的情况.S为当前行上的“插头”状态,每两个二进制位表示一个格子,设当前格子为(x,y ...

随机推荐

  1. selenium3 + python - iframe

    一.frame和iframe区别 Frame与Iframe两者可以实现的功能基本相同,不过Iframe比Frame具有更多的灵活性. frame是整个页面的框架,iframe是内嵌的网页元素,也可以说 ...

  2. BZOJ 2001 线段树+LCT (TLE)

    同是O(nlog^2n)怎么常数差距就这么大呢,,, 同是LCT  怎么我的和Po姐姐的常数差距就这么大呢 我绝对是脑子被驴踢了才写这个垃圾算法 //By SiriusRen #include < ...

  3. css3 绘制书本

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  4. React Component 生命周期

    一般而言 Component 有以下三种生命周期的状态: Mounting:已插入真实的 DOM Updating:正在被重新渲染 Unmounting:已移出真实的 DOM 针对 Component ...

  5. Hibernate 延迟加载剖析与代理模式应用

    本文来源于:http://www.ibm.com/developerworks/cn/java/j-lo-hibernatelazy/#icomments

  6. .mm c++ oc 混编

    When you create a static library you don't link in the dependent libraries. As a result, when you re ...

  7. post发送 ArrayBuffer

    // 用 POST 方法将 ArrayBuffer 发送到服务器 ); var longInt8View = new Uint8Array(myArray); ; i< longInt8View ...

  8. CAD绘制一个半径标注(com接口VB语言)

    主要用到函数说明: _DMxDrawX::DrawDimRadial 绘制一个半径标注.详细说明如下: 参数 说明 DOUBLE dCenterX 被标注的曲线的中点X值 DOUBLE dCenter ...

  9. Day10 图形用户界面和游戏开发

    基于tkinter模块的GUI GUI是图形用户界面的缩写,图形化的用户界面对使用过计算机的人来说应该都不陌生,在此也无需进行赘述.Python默认的GUI开发模块是tkinter(在Python 3 ...

  10. RESTful API 学习【第1篇】

    一. 什么是RESTful REST与技术无关,代表的是一种软件架构风格,REST是Representational State Transfer的简称,中文翻译为“表征状态转移” REST从资源的角 ...