稍稍变形的最长公共子序列
#pragma warning(disable:4996)
#include<stdio.h>
#include<string>
#include<algorithm>
using namespace std;
int dp[10010][10010];
int main()
{
int a[10010], b[10010];
int n, m, l;
scanf("%d", &n);
scanf("%d", &m);
for (int i = 1; i <= m; i++)
{
scanf("%d", &a[i]);
}
scanf("%d", &l);
for (int i = 1; i <= l; i++)
{
scanf("%d", &b[i]);
}
int lena = m;
int lenb = l;
for (int i = 0; i <= lena; i++)
{
dp[i][0] = 0;
}
for (int i = 0; i <= lenb; i++)
{
dp[0][i] = 0;
}
for (int i = 1; i <= lena; i++)
{
for (int j = 1; j <= lenb; j++)
{
if (a[i] == b[j])
{
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]) + 1;
}
else
{
dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
}
}
}
printf("%d", dp[lena][lenb]);
}