LCS的无敌大水题
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
#define maxn 500
int dp[maxn][maxn];
char str1[maxn],str2[maxn];
int main()
{
int i,j;
int m,n;
while(~scanf("%s%s",str1+1,str2+1))
{
memset(dp, 0, sizeof(dp));
m=strlen(str1+1);
n=strlen(str2+1);
for(i=1;i<=m;i++)
for(j=1;j<=n;j++)
if(str1[i]==str2[j])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[m][n]);
}
return 0;
}