Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<math.h>
- #include<cstring>
- using namespace std;
- int LCS(char str1[],char str2[],int l1,int l2){
- if(l1==0 ||l2==0)
- return 0;
- if(str1[l1-1]==str2[l2-1])
- return 1+LCS(str1,str2,l1-1,l2-1);
- return max(LCS(str1,str2,l1,l2-1),LCS(str1,str2,l1-1,l2));
- }
- int main(){
- char X[] = "AGGTAB";
- char Y[] = "GXTXAYB";
- int m = strlen(X);
- int n = strlen(Y);
- cout<<"Length of LCS is "<<LCS( X, Y, m, n ) ;
- return 0;
- }
Add Comment
Please, Sign In to add comment