给Eva想要的颜色编序号,之后就转换为求最长非递减上升子序列长度
#include<iostream>
#include<algorithm>
using namespace std;
int n, m, l, num;
const int maxn = 1e4 + 10;
int a[maxn], b[maxn], dp[maxn], x;
int main()
{
int ans = 0;
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++)
{
scanf("%d", &x);
a[x] = i;
}
scanf("%d", &l);
for (int i = 0; i < l; i++)
{
scanf("%d", &x);
if (a[x])
{
b[num] = a[x];
dp[num] = 1;
num++;
}
}
for (int i = 0; i < num; i++)
{
for (int j = 0; j < i; j++)
if (b[i] >= b[j])dp[i] = max(dp[i], dp[j] + 1);
ans = max(ans, dp[i]);
}
printf("%d", ans);
return 0;
}