-
-
Save fredbr/fbde2ae31f60b6fd5dfe2c5a0c023802 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//codigo de Lucio Cardoso | |
#include <bits/stdc++.h> | |
using namespace std; | |
const int MAXN = 1010; | |
int dp[MAXN][MAXN], s1[MAXN], s2[MAXN]; | |
// maior subsequência comum | |
int lcs(int a, int b) | |
{ | |
if (dp[a][b] != -1) return dp[a][b]; | |
if (a == 0 || b == 0) return dp[a][b] = 0; | |
if (s1[a] == s2[b]) return dp[a][b] = 1+lcs(a-1, b-1); | |
else return dp[a][b] = max(lcs(a-1, b), lcs(a, b-1)); | |
} | |
int main(void) | |
{ | |
int n, m; | |
cin >> n >> m; | |
memset(dp, -1, sizeof dp); | |
for (int i = 1; i <= n; i++) cin >> s1[i]; | |
for (int i = 1; i <= m; i++) cin >> s2[i]; | |
cout << n-lcs(n, m) << " " << m-lcs(n, m) << "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment