动态规划的题目
//这是一道设计序列的动态规划问题
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 10010;
int a[MAXN];
int happen[MAXN];
int dp[MAXN];
vector<int> signalColor;
int main(void)
{
freopen("pat0314/in.txt","r",stdin);
int n;
cin>>n;
int k;
cin>>k;
for(int i = 1;i<=k;i++)
{
cin>>a[i];
happen[a[i]] = i;
}
int m;
cin>>m;
for(int i = 1;i<=m;i++)
{
int num;
cin>>num;
if(happen[num] >= 1)
{
signalColor.push_back(happen[num]);
}
}
int maxlen = 0;
for(int i = 0;i<signalColor.size();i++)
{
// cout<<signalColor[i]<<" ";
dp[i] = 1;
for(int j = 0;j<i;j++)
{
if(signalColor[i] >= signalColor[j])
{
// dp[i] = dp[j] + 1;
dp[i] = max(dp[i],dp[j] + 1);
}
}
if(dp[i] > maxlen)
{
maxlen = dp[i];
}
}
cout<<maxlen<<endl;
return 0;
}