- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLCS.cpp
More file actions
Latest commit
31 lines (31 loc) · 538 Bytes
/
Copy pathLCS.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>
usingnamespacestd;
intmaximum(int p,int q){
return p>q?p:q;
}
intLCS(char *x,char *y,int m,int n)
{
if(m==0or n==0)
{
returnfalse;
}
if(x[m-1]==y[n-1])
{
return (1+LCS(x,y,m-1,n-1));
}
else
{
returnmaximum(LCS(x,y,m,n-1),LCS(x,y,m-1,n));
}
}
intmain(){
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);
return0;
}