传送门

太神仙了……讲不来讲不来->这里

 //minamoto
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define ll long long
using namespace std;
const int cube=1e9,mod=;
int n,m;
struct node{
int bit[];
inline void clear(){memset(bit,,sizeof(bit));}
node(){clear();}
inline void set(int t){clear();while(t)bit[++bit[]]=t%cube,t/=cube;}
inline int &operator [](int x){return bit[x];}
inline void print(){
printf("%d",bit[bit[]]);
for(int i=bit[]-;i;--i) printf("%09d",bit[i]);
putchar();
}
inline node operator +(node b){
node c;
c[]=max(bit[],b[])+;
for(int i=;i<=c[];++i)
c[i]+=bit[i]+b[i],c[i+]+=c[i]/cube,c[i]%=cube;
while(!c[c[]]) --c[];
return c;
}
inline void operator +=(node b){*this=*this+b;}
inline void operator =(int x){set(x);}
}ans;
struct Ha{
node val[mod];
int key[mod],sz,Hash[mod];
inline void init(){
memset(val,,sizeof(val)),memset(key,-,sizeof(key));
sz=,memset(Hash,,sizeof(Hash));
}
inline void newhash(int id,int v){Hash[id]=++sz,key[sz]=v;}
node &operator [](const int state){
for(int i=state%mod;;i=(i+==mod)?:i+){
if(!Hash[i]) newhash(i,state);
if(key[Hash[i]]==state) return val[Hash[i]];
}
}
}f[];
inline int find(int state,int id){return (state>>((id-)<<))&;}
inline void set(int &state,int bit,int val){bit=(bit-)<<,state|=<<bit,state^=<<bit,state|=val<<bit;}
int link(int state,int pos){
int cnt=,del=(find(state,pos)==)?:-;
for(int i=pos;i&&i<=m+;i+=del){
int plug=find(state,i);
if(plug==) ++cnt;
else if(plug==) --cnt;
if(!cnt) return i;
}
return -;
}
void solve(int x,int y){
int now=((x-)*m+y)&,last=now^,tot=f[last].sz;
f[now].init();
for(int i=;i<=tot;++i){
int state=f[last].key[i];
node val=f[last].val[i];
int plug1=find(state,y),plug2=find(state,y+);
if(link(state,y)==-||link(state,y+)==-) continue;
if(!plug1&&!plug2){if(x!=n&&y!=m)set(state,y,),set(state,y+,),f[now][state]+=val;}
else if(plug1&&!plug2){
if(x!=n) f[now][state]+=val;
if(y!=m) set(state,y,),set(state,y+,plug1),f[now][state]+=val;
}
else if(!plug1&&plug2){
if(y!=m) f[now][state]+=val;
if(x!=n) set(state,y,plug2),set(state,y+,),f[now][state]+=val;
}
else if(plug1==&&plug2==)
set(state,link(state,y+),),set(state,y,),set(state,y+,),f[now][state]+=val;
else if(plug1==&&plug2==){if(x==n&&y==m)ans+=val;}
else if(plug1==&&plug2==)set(state,y,),set(state,y+,),f[now][state]+=val;
else if(plug1==&&plug2==)
set(state,link(state,y),),set(state,y,),set(state,y+,),f[now][state]+=val;
}
}
int main(){
// freopen("testdata.in","r",stdin);
scanf("%d%d",&n,&m);
if(n==||m==) return puts(""),;
if(m>n) swap(n,m);
f[].init(),f[][]=;
for(int i=;i<=n;++i){
for(int j=;j<=m;++j) solve(i,j);
if(i!=n){
int now=(i*m)&,tot=f[now].sz;
for(int j=;j<=tot;++j)
f[now].key[j]<<=;
}
}
ans+=ans,ans.print();
return ;
}

洛谷P2289 [HNOI2004]邮递员(插头dp)的更多相关文章

  1. BZOJ.1210.[HNOI2004]邮递员(插头DP Hash 高精)

    BZOJ 洛谷 http://www.cnblogs.com/LadyLex/p/7326874.html 插头DP.\(m+1\)个插头的状态需要用三进制表示:\(0\)表示无插头,\(1\)表示是 ...

  2. 【BZOJ1210】[HNOI2004]邮递员 插头DP+高精度

    [BZOJ1210][HNOI2004]邮递员 Description Smith在P市的邮政局工作,他每天的工作是从邮局出发,到自己所管辖的所有邮筒取信件,然后带回邮局.他所管辖的邮筒非常巧地排成了 ...

  3. bzoj 1210 [HNOI2004] 邮递员 插头dp

    插头dp板子题?? 搞了我一晚上,还tm全是抄的标程.. 还有高精,哈希混入,还是我比较弱,orz各种dalao 有不明白的可以去看原论文.. #include<cstdio> #incl ...

  4. 洛谷P1437 [HNOI2004]敲砖块(dp)

    题目背景 无 题目描述 在一个凹槽中放置了 n 层砖块.最上面的一层有n 块砖,从上到下每层依次减少一块砖.每块砖 都有一个分值,敲掉这块砖就能得到相应的分值,如下图所示. 14 15 4 3 23 ...

  5. 洛谷 P5279 - [ZJOI2019]麻将(dp 套 dp)

    洛谷题面传送门 一道 dp 套 dp 的 immortal tea 首先考虑如何判断一套牌是否已经胡牌了,考虑 \(dp\)​​​​​.我们考虑将所有牌按权值大小从大到小排成一列,那我们设 \(dp_ ...

  6. 洛谷2344 奶牛抗议(DP+BIT+离散化)

    洛谷2344 奶牛抗议 本题地址:http://www.luogu.org/problem/show?pid=2344 题目背景 Generic Cow Protests, 2011 Feb 题目描述 ...

  7. Lightning Conductor 洛谷P3515 决策单调性优化DP

    遇见的第一道决策单调性优化DP,虽然看了题解,但是新技能√,很开森. 先%FlashHu大佬,反正我是看了他的题解和精美的配图才明白的,%%%巨佬. 废话不多说,看题: 题目大意 已知一个长度为n的序 ...

  8. 洛谷P1541 乌龟棋(四维DP)

    To 洛谷.1541 乌龟棋 题目背景 小明过生日的时候,爸爸送给他一副乌龟棋当作礼物. 题目描述 乌龟棋的棋盘是一行N个格子,每个格子上一个分数(非负整数).棋盘第1格是唯一的起点,第N格是终点,游 ...

  9. 【洛谷】P1052 过河【DP+路径压缩】

    P1052 过河 题目描述 在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有一些石子,青蛙很讨厌踩在这些石子上.由于桥的长度和青蛙一次跳过的距离都是正整数,我们可以把独木桥上青蛙 ...

随机推荐

  1. opencv操作相机相关函数

    1.基本操作 capture = cv2.VideoCapture(0) ret, image = capture.read() cv2.imwrite("photo.jpg", ...

  2. vi中如何替换某字符成“回车”?

    vi中如何替换某字符成“回车”? 在 vi 中::s/,/^M/g (you need to type CTRL-V <CR> to get a ^M here)VIM - Vi IMpr ...

  3. Java for LeetCode 096 Unique Binary Search Trees

    Given n, how many structurally unique BST's (binary search trees) that store values 1...n? For examp ...

  4. SQL语法之初级增删改查

    SQL语法之初级增删改查 1.增 1.1插入单行 INSERT INTO [表名](列名) VALUES(列值) 语法如下: INSERT INTO bsp_Nproductclass(guid,pi ...

  5. 修改织梦DedeCms文章页默认title的方法

    <title>{dede:field.title/}_{dede:field name='typeid' runphp='yes'}$id=@me;global $dsql;$sql=&q ...

  6. 算法(Algorithms)第4版 练习 1.3.26

    方法实现: //1.3.26 /** * remove all of the nodes in the list that have key as its item field * * @param ...

  7. 读《nodejs开发指南》记录

    最近看了一下<nodejs开发指南>发现nodejs在某些特定的领域由他自己的长处,适合密集计算但是业务逻辑比较简单的场景,如果做网站还是选择php吧,呵呵,这本书我除了第5章<用n ...

  8. Dual Path Networks(DPN)——一种结合了ResNet和DenseNet优势的新型卷积网络结构。深度残差网络通过残差旁支通路再利用特征,但残差通道不善于探索新特征。密集连接网络通过密集连接通路探索新特征,但有高冗余度。

    如何评价Dual Path Networks(DPN)? 论文链接:https://arxiv.org/pdf/1707.01629v1.pdf在ImagNet-1k数据集上,浅DPN超过了最好的Re ...

  9. C语言实现wc基本功能

    GitHub地址:https://github.com/hhx007/wc 项目要求 wc.exe 是一个常见的工具,它能统计文本文件的字符数.单词数和行数. 这个项目要求写一个命令行程序,模仿已有w ...

  10. IOC/DI控制反转与依赖注入

    IOC/DI控制反转与依赖注入 IOC和DI表现的效果的是一样的只不过对于作用的对象不同,有了不一样的名字. 先用一个现实的例子来说明IOC/DI表现出来的效果.