题意:
给俩字符串,求最长公共子序列。
解析:
!!!!!!!!!!
字符串里面含空格。
!!!!!!!!!!
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <stack>
#include <vector>
#include <queue>
#include <map>
#define LL long long
using namespace std;
const int maxn = 1e3 + 10;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const double pi = 4 * atan(1.0);
const double ee = exp(1.0);
char a[maxn], b[maxn];
LL dp[maxn][maxn];
int main()
{
#ifdef LOCAL
freopen("in.txt", "r", stdin);
#endif // LOCAL
while (gets(a))///空格毁ac...
{
gets(b);
int lena = strlen(a);
int lenb = strlen(b);
memset(dp, 0, sizeof(dp));
for (int i = 1; i <= lena; i++)
{
for (int j = 1; j <= lenb; j++)
{
if (a[i - 1] == b[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("%lld\n", dp[lena][lenb]);
}
return 0;
}