题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=36
纯模板。。
代码:
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char s[1005];
char s1[1005];
int dp[1005][1005];
int main()
{
int n;
while(~scanf("%d",&n))
{
while(n--)
{
memset(dp,0,sizeof dp);
scanf("%s%s",s,s1);
int len_s = strlen(s);
int len_s1 = strlen(s1);
for(int i = 1;i <= len_s;++i)
{
for(int j = 1;j <= len_s1;++j)
{
if(s[i - 1] == s1[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[len_s][len_s1]);
}
}
return 0;
}