-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLCS.cpp
More file actions
31 lines (31 loc) · 538 Bytes
/
LCS.cpp
File metadata and controls
31 lines (31 loc) · 538 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include<iostream>
using namespace std;
int maximum(int p,int q){
return p>q?p:q;
}
int LCS(char *x,char *y,int m,int n)
{
if(m==0 or n==0)
{
return false;
}
if(x[m-1]==y[n-1])
{
return (1+LCS(x,y,m-1,n-1));
}
else
{
return maximum(LCS(x,y,m,n-1),LCS(x,y,m-1,n));
}
}
int main(){
int p,q;
cout<<"Enter the size of first and second input : \n";
cin>>p>>q;
char X[p];
char Y[q];
cout<<"Enter the element in LCS : \n";
cin>>X>>Y;
cout<<"Length of LCS is : "<<LCS(X,Y,p,q);
return 0;
}