C - Common Subsequence
题目链接:http://acm.hust.edu.cn/vjudge/contest/126708#problem/C
就是求有多少个相同的元素:
代码如下:
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int s[1005][1005];
int main()
{
char a[1000],b[1000];
while(scanf("%s%s",a,b)==2)
{
memset(s,0,sizeof(s));
for(int i=1;i<=strlen(a);i++)
for(int j=1;j<=strlen(b);j++)
{
if(a[i-1]==b[j-1])
s[i][j]=s[i-1][j-1]+1;
else s[i][j]=max(s[i-1][j],s[i][j-1]);
}
printf("%d\n",s[strlen(a)][strlen(b)]);
}
return 0;
}