Skip to content

Commit 3690ea3

Browse files
authored
Merge pull request #15 from rohitthapliyal2000/patch-2
Create LCS.cpp
2 parents 22b6701 + 4eeb302 commit 3690ea3

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

LCS.cpp

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
int max(int a, int b);
5+
6+
int lcs( char *X, char *Y, int m, int n )
7+
{
8+
if (m == 0 || n == 0)
9+
return 0;
10+
if (X[m-1] == Y[n-1])
11+
return 1 + lcs(X, Y, m-1, n-1);
12+
else
13+
return max(lcs(X, Y, m, n-1), lcs(X, Y, m-1, n));
14+
}
15+
16+
int main()
17+
{
18+
char X[] = "AGGTAB";
19+
char Y[] = "GXTXAYB";
20+
21+
int m = strlen(X);
22+
int n = strlen(Y);
23+
24+
cout << lcs( X, Y, m, n ) ;
25+
return 0;
26+
}

0 commit comments

Comments
 (0)