- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlcs.cpp
More file actions
Latest commit
39 lines (29 loc) · 520 Bytes
/
Copy pathlcs.cpp
File metadata and controls
39 lines (29 loc) · 520 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
32
33
34
35
36
37
38
39
#include<bits/stdc++.h>
usingnamespacestd;
intlcs(string s, string t)
{
int len1 = s.size();
int len2 = t.size();
int arr[len1+1][len2+1];
memset(arr,0,sizeof arr);
int ans =0;
for(int i=1;i<=len1;i++)
{
for(int j =1;j<=len2;j++)
{
if(s[i-1] == t[j-1])
arr[i][j] = arr[i-1][j-1] +1;
else
arr[i][j] = max(arr[i-1][j],arr[i][j-1]);
ans = max(ans, arr[i][j]);
}
}
return ans;
}
intmain()
{
string s,t;
cin>>s>>t;
cout<<lcs(s,t);
return0;
}