#include <iostream>
#include <vector>
using namespace std;
int lcsLength(vector<char>& array1, vector<char>& array2)
{
// 初始化
int m = array1.size();
int n = array2.size();
int lcs[m][n];
for(int i=0; i<m; i++){
for (int j=0; j<n; j++){
lcs[i][j] = 0;
}
}
for (int i=1; i<m; i++){
for (int j=1; j<n; j++){
if(array1[i] == array2[j]){
lcs[i][j] = lcs[i-1][j-1]+1;
}
else if(lcs[i-1][j] > lcs[i][j-1]){
lcs[i][j] = lcs[i-1][j];
}
else{
lcs[i][j] = lcs[i][j-1];
}
}
}
return lcs[m][n];
}
int main() {
vector<char> array1 = {'g', 'o', 'o', 'd', 'm', 'o', 'r', 'n', 'i', 'n', 'g'};
vector<char> array2 = {'g', 'o', 'o', 'd'};
vector<char> array3 = {'m', 'o', 'r', 'n', 'i', 'n', 'g'};
cout << lcsLength(array1, array2) << endl;
cout << lcsLength(array1, array3) << endl;
return 0;
}