File tree Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Expand file tree Collapse file tree 1 file changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+
3
+ #include < bits/stdc++.h>
4
+ #define ll long long
5
+ #define ull unsigned long long
6
+ #define endl ' \n '
7
+ #define pb push_back
8
+ #define mp make_pair
9
+ #define sp (x ) fixed<<setprecision(x)
10
+ #define p_q priority_queue
11
+ #define fast_io ios_base::sync_with_stdio (0 );cin.tie(NULL );cout.tie(NULL );
12
+ using namespace std ;
13
+
14
+ int lcs (string x, string y, int m, int n)
15
+ {
16
+ int dp[m+1 ][n+1 ];
17
+
18
+ for (int i=0 ;i<=m;i++)
19
+ {
20
+ for (int j=0 ;j<=n;j++)
21
+ {
22
+ if (i==0 || j==0 )
23
+ dp[i][j] = 0 ;
24
+
25
+ else if (x[i-1 ] == y[j-1 ])
26
+ dp[i][j] = 1 + dp[i-1 ][j-1 ];
27
+
28
+ else
29
+ dp[i][j] = max ( dp[i][j-1 ], dp[i-1 ][j] );
30
+ }
31
+ }
32
+
33
+ return dp[m][n];
34
+ }
35
+
36
+ int main ()
37
+ {
38
+
39
+ fast_io;
40
+
41
+ string x,y;
42
+ cin>>x>>y;
43
+
44
+ int m = x.length (), n = y.length ();
45
+
46
+ cout<<lcs (x,y,m,n)<<endl;
47
+
48
+ return 0 ;
49
+ }
You can’t perform that action at this time.
0 commit comments