AcWing 272. 最长公共上升子序列
原题链接
中等
作者:
像雾像雨又像f风
,
2020-04-16 17:46:47
,
所有人可见
,
阅读 616
#include<iostream>
#include<algorithm>
using namespace std ;
const int N = 3010;
int n,a[N],b[N],f[N][N];
int main()
{
scanf("%d",&n);
for(int i = 1;i<=n; ++i)scanf("%d",&a[i]);
for(int i = 1;i<=n; ++i)scanf("%d",&b[i]);
for (int i = 1; i <= n; i ++ )
{
int maxv = 1;
for (int j = 1; j <= n; j ++ )
{
f[i][j] = f[i - 1][j];
if(a[i]==b[j]) f[i][j] = max(maxv,f[i][j]);
if(a[i]>b[j]) maxv = max(maxv,f[i-1][j] + 1);
}
}
int res = 0;
for(int i =1 ;i<= n ;++ i)res = max(f[n][i],res);
cout << res ;
return 0;
}