[BZOJ1264][AHOI2006]基因匹配Match(DP + 树状数组)


传送门

有点类似LCS,可以把 a[i] 在 b 串中的位置用一个链式前向星串起来,由于链式前向星是从后往前遍历,所以可以直接搞。

状态转移方程 f[i] = max(f[j]) + 1 ( 1 <= j < i && a[i] == b[j] )

——代码

1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 5 using namespace std; 6 7 const int MAXN = 200001; 8 int n, cnt, ans; 9 int a[MAXN], c[MAXN]; 10 int head[MAXN], to[MAXN << 4], next[MAXN << 4]; 11 12 inline int query(int x) 13 18 19 inline void update(int x, int d) 20 23 24 inline void add(int x, int y) 25 30 31 int main() 32 46 printf("%d", ans); 47 return 0; 48 }
View Code



上一篇:[luoguP1440] 求m区间内的最小值(单调队列 || 线段树)

下一篇:[luoguP2617] Dynamic Ranking(树状数组 套 主席树 + 离散化)


DP 树状数组
Copyright © 2002-2019 k262电脑网 www.k262.cn 皖ICP备2020016292号
温馨提示:部分文章图片数据来源与网络,仅供参考!版权归原作者所有,如有侵权请联系删除!QQ:251442993 热门搜索 网站地图