Problem: 2050E - Three Strings
Language: C++17 (GCC 7-32)

Previous submission (verdict: Compilation error):
#include <iostream>
#include <stack>

using namespace std;
vector<vector<int>> dp;
int rec(string &a, string &b, string &c, int i, int j) {
    if(i == a.size() && j == b.size()) return 0;
    int pos = i+j;
    int res = INT_MAX;
    if(i < a.length()) {
        int cost = rec(a,b,c,i+1,j) + (a[i] != c[pos]);
        res = min(res, cost);
    }
    if(j < b.length()) {
        int cost = rec(a,b,c,i,j+1) + (b[j] != c[pos]);
        res = min(res, cost);
    }
    return res;
}

int mem(string &a, string &b, string &c, int i, int j) {
    if(i == a.size() && j == b.size()) return 0;
    if(dp[i][j] != -1) return dp[i][j];
    int pos = i+j;
    int res = INT_MAX;
    if(i < a.length()) {
        int cost = mem(a,b,c,i+1,j) + (a[i] != c[pos]);
        res = min(res, cost);
    }
    if(j < b.length()) {
        int cost = mem(a,b,c,i,j+1) + (b[j] != c[pos]);
        res = min(res, cost);
    }
    return dp[i][j] = res;
}

int tab(string &a, string &b, string &c) {
    dp[a.length()][b.length()] = 0;
    for(int j=0;j<b.length(); j++) dp[a.length()][j] = 0;
    for(int i=0;i<a.length(); i++) dp[i][b.length()] = 0;
    for(int i=a.length()-1;i >= 0; i--) {
        for(int j=b.length()-1; j >= 0; j--) { 
            int pos = i+j;
            int res = INT_MAX;
            if(i < a.length()) {
                int cost = dp[i+1][j] + (a[i] != c[pos]);
                res = min(res, cost);
            }
            if(j < b.length()) {
                int cost = dp[i][j+1] + (b[j] != c[pos]);
                res = min(res, cost);
            }
            dp[i][j] = res;         
        }
    }
    return dp[0][0];
}
int main() {
    #ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
    int t;
    cin >> t;
    string a, b, c;
    while (t--) {
        cin>>a>>b>>c; 
        dp.assign(a.length() + 1, vector<int> (b.length()+1, -1));
        //cout<<rec(a,b,c,0,0)<<'\n'
        cout<<mem(a,b,c,0,0)<<'\n';
        // cout<<tab(a,b,c)<<'\n';        
    }
}

/*
  
1 2 3 4 5
6 2 1 4 2
6 2 0 4 3
5 2 1 4 3
5 3 1 3 3
4 3 2 3 3
3 3 3 3 3

6 2 1 4 2
3 2 4 4 2
3 3 4 3 2
3 3 3 3 3

4 2 1 5 3

4 2 1 5 3
4 3 1 4 3

*/

Submission (verdict: Accepted):
#include <iostream>
#include <vector>

using namespace std;
vector<vector<int>> dp;
int rec(string &a, string &b, string &c, int i, int j) {
    if(i == a.size() && j == b.size()) return 0;
    int pos = i+j;
    int res = INT_MAX;
    if(i < a.length()) {
        int cost = rec(a,b,c,i+1,j) + (a[i] != c[pos]);
        res = min(res, cost);
    }
    if(j < b.length()) {
        int cost = rec(a,b,c,i,j+1) + (b[j] != c[pos]);
        res = min(res, cost);
    }
    return res;
}

int mem(string &a, string &b, string &c, int i, int j) {
    if(i == a.size() && j == b.size()) return 0;
    if(dp[i][j] != -1) return dp[i][j];
    int pos = i+j;
    int res = INT_MAX;
    if(i < a.length()) {
        int cost = mem(a,b,c,i+1,j) + (a[i] != c[pos]);
        res = min(res, cost);
    }
    if(j < b.length()) {
        int cost = mem(a,b,c,i,j+1) + (b[j] != c[pos]);
        res = min(res, cost);
    }
    return dp[i][j] = res;
}

int tab(string &a, string &b, string &c) {
    dp[a.length()][b.length()] = 0;
    for(int j=0;j<b.length(); j++) dp[a.length()][j] = 0;
    for(int i=0;i<a.length(); i++) dp[i][b.length()] = 0;
    for(int i=a.length()-1;i >= 0; i--) {
        for(int j=b.length()-1; j >= 0; j--) { 
            int pos = i+j;
            int res = INT_MAX;
            if(i < a.length()) {
                int cost = dp[i+1][j] + (a[i] != c[pos]);
                res = min(res, cost);
            }
            if(j < b.length()) {
                int cost = dp[i][j+1] + (b[j] != c[pos]);
                res = min(res, cost);
            }
            dp[i][j] = res;         
        }
    }
    return dp[0][0];
}
int main() {
    #ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
    int t;
    cin >> t;
    string a, b, c;
    while (t--) {
        cin>>a>>b>>c; 
        dp.assign(a.length() + 1, vector<int> (b.length()+1, -1));
        //cout<<rec(a,b,c,0,0)<<'\n'
        cout<<mem(a,b,c,0,0)<<'\n';
        // cout<<tab(a,b,c)<<'\n';        
    }
}

/*
  
1 2 3 4 5
6 2 1 4 2
6 2 0 4 3
5 2 1 4 3
5 3 1 3 3
4 3 2 3 3
3 3 3 3 3

6 2 1 4 2
3 2 4 4 2
3 3 4 3 2
3 3 3 3 3

4 2 1 5 3

4 2 1 5 3
4 3 1 4 3

*/