openjudge-NOI 2.6-1808 公共子序列
题目链接:http://noi.openjudge.cn/ch0206/1808/
题解:
裸题……
1 #include<cstdio> 2 #include<cstring> 3 #define MAXN 2010 4 int lena,lenb,ans1,ans2[MAXN],f[MAXN][MAXN]; 5 char a[MAXN],b[MAXN]; 6 inline int max(int x,int y) 7 { 8 return x>y?x:y; 9 } 10 int main() 11 { 12 while(scanf("%s%s",a+1,b+1)!=EOF) 13 { 14 memset(f,0,sizeof(f)); 15 lena=strlen(a+1);lenb=strlen(b+1); 16 for(int i=1;i<=lena;++i) 17 for(int j=1;j<=lenb;++j) 18 { 19 if(a[i]==b[j])f[i][j]=f[i-1][j-1]+1; 20 else f[i][j]=max(f[i-1][j],f[i][j-1]); 21 } 22 printf("%d\n",f[lena][lenb]); 23 } 24 return 0; 25 }