Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- string a, b;
- int dp[1001][1001];
- int rec(int i, int j) {
- if(i < 0 or j < 0) {
- return 0;
- }
- if(dp[i][j] != -1) {
- return dp[i][j];
- }
- int res = 0;
- res = max(res, rec(i - 1, j));
- res = max(res, rec(i, j - 1));
- if(a[i] == b[j]) {
- res = max(res, rec(i - 1, j - 1) + 1);
- }
- dp[i][j] = res;
- return res;
- }
- int main()
- {
- cin >> a >> b;
- memset(dp, -1, sizeof dp);
- cout << rec(a.size() - 1, b.size() - 1) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement