DP-LIS and LCS

Posted iamiron-man

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了DP-LIS and LCS相关的知识,希望对你有一定的参考价值。

最长上升子串
f[i]=f[I-1]+1(f[I]>f[I-1])
f[I]=1;(f[I]<=f[I-1])
输出max(f(I))
最长上升子序列
f[I]=max(f[I],f[j]+1);

For example:D. Remove One Element http://codeforces.com/contest/1272/problem/D

左边扫一遍,右边扫一遍,然后好用
```c++

include<bits/stdc++.h>

using namespace std;
int Dpl[200010], a[200010], Dpr[200010];
int n;
int main()
{
cin >> n;
for (int i = 1;i <= n;++i)
cin >> a[i];
int ans = 1;
Dpl[1] = Dpr[n] = 1;
for (int i = 2;i <= n;++i)
{
if (a[i] > a[i-1])
Dpl[i] = Dpl[i-1]+1;
else
Dpl[i] = 1;
}
for (int i = n-1;i >= 1;--i)
{
if (a[i] < a[i+1])
Dpr[i] = Dpr[i+1]+1;
else
Dpr[i] = 1;
}
for (int i = 2;i <= n;++i)
{
ans = max(ans, Dpl[i]);
if (a[i] > a[i-2])
ans = max(ans, Dpl[i-2]+Dpr[i]);
}
cout << ans;
return 0;
}

以上是关于DP-LIS and LCS的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces 463D Gargari and Permutations:隐式图dp多串LCS

CF463D Gargari and Permutations (LCS)

Codeforces 463D Gargari and Permutations(求k个序列的LCS)

CodeForces 163A Substring and Subsequence

2018 Multi-University Training Contest 5 1008 / hdu6357 Hills And Valleys LCS,思维

hdu 5495 LCS(并查集)