Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<vector>
- #include<algorithm>
- #include <string>
- using namespace std;
- int main() {
- int N = 0, M = 0;
- cin >> N;
- vector<int> X(N + 1);
- for (int i = 1; i <= N; i++) cin >> X[i];
- cin >> M;
- vector<int> Y(M + 1);
- for (int j = 1; j <= M; j++)
- cin >> Y[j];
- vector<vector<int>> LCS(N + 1, vector<int>(M + 1, 0));
- for (int i = 1; i <= N; i++) {
- for (int j = 1; j <= M; j++)
- if (X[i] == Y[j]) LCS[i][j] = LCS[i - 1][j - 1] + 1;
- else LCS[i][j] = max(LCS[i - 1][j], LCS[i][j - 1]);
- }
- cout << LCS[N][M];
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement