#include<stdio.h> #include<string.h>
char line1[100],line2[100]; int LCS(int,int); int best(int,int); //int lcsdp[100][100];
void main() { int l1,l2; /* for(int i=0;i<100;++i) for(int j=0;j<100;++j) lcsdp[i][j]=-1;*/
//while(gets(line1) && gets(line2)) gets(line1); gets(line2); l1=strlen(line1); l2=strlen(line2);
printf("%d\n",LCS(l1-1,l2-1)); }
int LCS(int i,int j) { if((i<0)||(j<0))return 0; //if(lcsdp[i][j]>-1)return lcsdp[i][j]; if(line1[i]==line2[j]){ //lcsdp[i][j]= return LCS(i-1,j-1)+1; //return lcsdp[i][j]; } int res1=LCS(i-1,j); int res2=LCS(i,j-1); //lcsdp[i][j]=best(res1,res2); return best(res1,res2); //return lcsdp[i][j];
return 1; }
int best(int m,int n) { if(m>n) return m; else return n;
return 0; }
|