Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- #include<math.h>
- using namespace std;
- int LCS(char str1[],char str2[],int l1,int l2){
- if(l1==0 ||l2==0)
- return 0;
- int arr[l1+1][l2+1];
- for(int i=0;i<=l1;i++){
- for(int j=0;j<=l2;j++){
- if(i==0 || j==0)
- arr[i][j]=0;
- else{
- if(str1[i-1]==str2[j-1])
- arr[i][j]=1+arr[i-1][j-1];
- else
- arr[i][j]=max(arr[i][j-1],arr[i-1][j]);
- }
- }
- }
- return arr[l1][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