题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1159
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=500+5;
char s1[maxn],s2[maxn];
int d[maxn][maxn];
int main()
{int i,j;while(scanf("%s %s",s1,s2)!=EOF){memset(d,0,sizeof(d));for(i=0;s1[i];i++)for(j=0;s2[j];j++)if(s1[i]==s2[j]) d[i][j]=i>=1&&j>=1?d[i-1][j-1]+1:1;else d[i][j]=max(i>=1?d[i-1][j]:0,j>=1?d[i][j-1]:0);cout<<d[i-1][j-1]<<endl;}return 0;
}