Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 421 ms):
#include <bits/stdc++.h>
using namespace std;
int ar[1001][1001]; //ar[a][b] la gia tri minimum cua de bai khi day st1 co a phan tu dau tien, 
                    //st2 co b phan tu dau tien, va st co a+b phan tu dau tien

int minn (int a, int b){
    if (a<b) return a;
    return b;
}
//ab 
//ba 
//aabb

/*
void dp (string st1, int s1, string st2, int s2, string st){
    //s1 la do dai chuoi st1, s1 la do dai chuoi st2
    //s1, s2 la so luong phan tu nhe, trong ham main thi ghi la 
    // dp(st1, st1.length(), st2, st2.length(), st)
    int a = s1;
    int b = s2;
    // truong hop co so 
    if (a==0){
        if (ar[0][b-1]==-1) dp(st1, 0, st2, b-1, st);
        if (st[b-1]==st2[b-1]) ar[0][b]=ar[0][b-1];
        else ar[0][b]=ar[0][b-1]+1;
        return;
    }
    if (b==0){
        if (ar[0][b-1]==-1) dp(st1, 0, st2, b-1, st);
        if (st[a-1]==st1[a-1]) ar[a][0]=ar[a-1][0];
        else ar[a][0]=ar[a-1][0]+1;
        return;
    }
    // xu ly
    // so sanh st[i] voi st1[a] va st2[b]
    // neu st[i] bang mot trong hai thi ar[a][b]=(ar[a-1][b] HOAC ar[a][b-1])
    // neu st[i] bang ca hai thi ar[a][b]= MIN(ar[a-1][b] VA ar[a][b-1])
    // neu st[i] khac ca hai thi ar[a][b]= MIN(ar[a-1][b] VA ar[a][b-1]) + 1
    // tat nhien la phai check xem ar[a-1][b] co ton tai ko, neu ko thi = dp (...)
    int i=a+b-1;
    if (ar[a-1][b]==-1) {
        dp(st1, a-1, st2, b, st);
    }
    if (ar[a][b-1]==-1) {
        dp(st1, a, st2, b-1, st);
    }
    // --------------------------------------
    if (st[i]==st1[a-1] && st[i]==st2[b-1]){
        int mini = minn(ar[a-1][b], ar[a][b-1]);
        ar[a][b]=mini;
    }
    else if (st[i]!=st1[a-1] && st[i]==st2[b-1]) {
        ar[a][b]=minn(ar[a][b-1], ar[a-1][b]+1);
    }
    else if (st[i]==st1[a-1] && st[i]!=st2[b-1]) {
        ar[a][b]=minn(ar[a-1][b], ar[a][b-1]+1);
    }
    else {
        int mini = minn(ar[a-1][b], ar[a][b-1]) + 1;
        ar[a][b]=mini;
    }
}
*/
void dp(string st1, string st2, string st) {
    int a = st1.length();
    int b = st2.length();
    for (int i = 0; i <= a; ++i) {
        for (int j = 0; j <= b; ++j) {
            if (i == 0 && j == 0) continue;
            if (i == 0) {
                ar[i][j] = ar[i][j-1] + (st[i+j-1] != st2[j-1]);
            } else if (j == 0) {
                ar[i][j] = ar[i-1][j] + (st[i+j-1] != st1[i-1]);
            } else {
                int cost1 = ar[i-1][j] + (st[i+j-1] != st1[i-1]);
                int cost2 = ar[i][j-1] + (st[i+j-1] != st2[j-1]);
                ar[i][j] = min(cost1, cost2);
            }
        }
    }
}

// e   g   g
// ann    ie
// egaeg   ae   g
int main() {
    int test;
    cin>>test;
    string st, st1, st2;
    for (int it=0; it<test; it++){
        cin>>st1>>st2>>st;
        for (int i=0; i<1001; i++){
            for (int j=0; j<1001; j++){
                ar[i][j]=-1;
            }
        }
        if (st[0]==st1[0]) ar[1][0]=0; else ar[1][0]=1;
        if (st[0]==st2[0]) ar[0][1]=0; else ar[0][1]=1;//bang 1 het do
        dp(st1, st2, st); //dp(a, 1, bcd, 3, decf)
        cout<<ar[st1.length()][st2.length()]+1<<"\n";
    }
    return 0;
}

Solution 2 (runtime: 2421 ms):
#include<bits/stdc++.h>
#define int long long 
using namespace std;
int helper(int index1,int index2,int index3,int n,int m,int k,string &a,string&b,string &c,unordered_map<string,int>&mp){
    if(index1==n&&index2==m){
        return 0;
    }
    int taken=INT_MAX;
    int taken2=INT_MAX;
    string temp=to_string(index1)+"*"+to_string(index2);
    if(mp.find(temp)!=mp.end()){
        return mp[temp];
    }
    if(index1<n){
        if(a[index1]==c[index3]){
            taken=helper(index1+1,index2,index3+1,n,m,k,a,b,c,mp);
        }
        else taken=1+helper(index1+1,index2,index3+1,n,m,k,a,b,c,mp);
    }
    if(index2<m){
          if(b[index2]==c[index3]){
            taken2=helper(index1,index2+1,index3+1,n,m,k,a,b,c,mp);
        }
        else taken2=1+helper(index1,index2+1,index3+1,n,m,k,a,b,c,mp);
    }
    return mp[temp]=min(taken,taken2);
}
 void solve(){
string a,b,c;
cin >> a >> b >> c;
int n=a.size();
int m=b.size();
int k=c.size();
unordered_map<string,int>mp;
int ans=helper(0,0,0,n,m,k,a,b,c,mp);
cout << ans << endl;
 }
signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}