Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int T;
- cin >> T;
- while(T--) {
- int N, M;
- cin >> N >> M;
- string s, t;
- cin >> s >> t;
- vector < vector < int > > dp(N + 1, vector < int >(M + 1));
- for(int i = 1; i <= N; ++i)
- for(int j = 1; j <= M; ++j) {
- if(s[i - 1] == t[j - 1])
- dp[i][j] = dp[i - 1][j - 1] + 1;
- else
- dp[i][j] = max(dp[i][j], max(dp[i - 1][j], dp[i][j - 1]));
- }
- cout << dp[N][M] << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment