Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // https://codeforces.com/contest/2050/problem/E
- #include <iostream>
- using namespace std;
- typedef long long ll;
- const int INF = 1e9;
- int dp[1001][1001];
- void solve()
- {
- string a, b, c;
- cin >> a >> b >> c;
- for(int i = 0;i<=a.length();i++)
- for(int j = 0;j<=b.length();j++)
- {
- if(i == 0 && j == 0) continue;
- dp[i][j] = INF;
- int aPoz = i-1, bPoz = j-1, cPoz = i + j - 1;
- if(j-1>=0)
- dp[i][j] = min(dp[i][j], dp[i][j-1] + (b[bPoz] != c[cPoz]));
- if(i-1>=0)
- dp[i][j] = min(dp[i][j], dp[i-1][j] + (a[aPoz] != c[cPoz]));
- }
- int aLen = a.length(), bLen = b.length(), cLen = c.length();
- cout << min(dp[aLen][cLen-aLen],dp[cLen-bLen][bLen]) << '\n';
- for(int i = 0;i<=a.length();i++)
- for(int j = 0;j<=b.length();j++)
- dp[i][j] = 0;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0); cout.tie(0);
- int t; cin >> t;
- while(t--) solve();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement