Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int longestSubsequence(string x, string y) {
- int n = x.size(), m = y.size();
- vector<vector<int>> dp(n + 1, vector<int>(m + 1, 0));
- // Compute the longest common subsequence that is also a substring
- int maxLength = 0;
- for (int i = 1; i <= n; i++) {
- for (int j = 1; j <= m; j++) {
- if (x[i - 1] == y[j - 1]) {
- dp[i][j] = dp[i - 1][j - 1] + 1;
- maxLength = max(maxLength, dp[i][j]);
- }
- }
- }
- return maxLength;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement