OpenJudge1808:公共子序列
题目链接
动态规划的题型
#include<iostream>
#include<cstring>
using namespace std;
char a[210], b[210];
int c[210][210] = { 0 };
int main() {
while (cin >> a >> b) {
int lena = strlen(a);
int lenb = strlen(b);
for (int i = 1; i <= lena; i++) {
for (int j = 1; j <= lenb; j++) {
if (a[i - 1] == b[j - 1])
c[i][j] = c[i - 1][j - 1]+1;
else {
c[i][j] = max(c[i - 1][j], c[i][j - 1]);
}
}
}
cout << c[lena][lenb] << endl;
}
return 0;
}