Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <algorithm>
- #include <queue>
- #include <vector>
- using namespace std;
- typedef long long ll;
- int dp[1005][1005];
- int main() {
- string a, b;
- cin >> a >> b;
- for(int i = 0; i <= a.size(); i++) {
- for(int j = 0; j <= b.size(); j++) {
- dp[i][j] = -2e9;
- }
- }
- dp[0][0] = 0;
- int result = 0;
- for(int i = 0; i < a.size(); i++) {
- for(int j = 0; j < b.size(); j++) {
- if(a[i] == b[j]) {
- dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
- }
- dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
- dp[i][j + 1] = max(dp[i][j + 1], dp[i][j]);
- }
- }
- for(int i = 0; i <= a.size(); i++) {
- for(int j = 0; j <= b.size(); j++) {
- result = max(result, dp[i][j]);
- }
- }
- cout << result << endl;
- return 0;
- }
- /*
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement