feat: problem partialy formatted
This commit is contained in:
25
longest-common-subsequence/src/ac.cpp
Normal file
25
longest-common-subsequence/src/ac.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int memo[1011][1011];
|
||||
|
||||
int solve(string &s1, string &s2, int i = 0, int j = 0)
|
||||
{
|
||||
if (i == s1.size() || j == s2.size()) return 0;
|
||||
if (memo[i][j] != - 1) return memo[i][j];
|
||||
|
||||
if (s1[i] == s2[j]) {
|
||||
return memo[i][j] = (solve(s1, s2, i + 1, j + 1) + 1);
|
||||
}
|
||||
return memo[i][j] = max(solve(s1, s2, i, j + 1), solve(s1, s2, i + 1, j));
|
||||
}
|
||||
|
||||
int main(){
|
||||
string s1, s2; cin >> s1 >> s2;
|
||||
memset(memo, -1, sizeof(memo));
|
||||
|
||||
cout << solve(s1, s2) << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user