-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha.c
More file actions
29 lines (28 loc) · 652 Bytes
/
a.c
File metadata and controls
29 lines (28 loc) · 652 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
#include <stdio.h>
#include <string.h>
int lcs(char a[],char b[],int m,int n){
int l[m+1][n+1];
for (int i = 0; i <=m; i++)
{
for (int j = 0; j <=n; j++)
{
if(i==0 || j==0){
l[i][j]=0;
}
else if(a[i-1]==b[j-1]){
l[i][j] = l[i-1][j-1] +1;
}
else{
l[i][j] = (l[i-1][j]>l[i][j-1])?l[i-1][j]:l[i][j-1];
}
}
}
return l[m][n];
}
int main(){
char s1[]= "abc";
char s2[]= "bc";
int m = strlen(s1);
int n = strlen(s1);
printf("length of lcs is %d\n",lcs(s1,s2,m,n));
}