题目大意:给出字符串 X 和 Y,输出最长公共子序列的长度
解题思路:LCS 水过
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<string.h>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
const int INF = 0x3f3f3f3f;
const int NINF = -INF -1;
const int MAXN = 10000+5;
using namespace std;
string x, y;
int dp[MAXN][MAXN];
int main() {
while (cin >> x >> y) {
for (int i = 1; i <= x.length(); i++)
for (int j = 1; j <= y.length(); j++) {
if (x[i-1] == y[j-1])
dp[i][j] = dp[i-1][j-1] + 1;
else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
}
printf("%d\n", dp[x.length()][y.length()]);
}
return 0;
}