传送门
有点类似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
上一篇:[Vijos1617] 超级教主(DP + 单调队列)
下一篇:[HDU2136] Largest prime factor(素数筛)
DP 树状数组









