Problem: 2050E - Three Strings
Language: java

Solution 1 (runtime: 343 ms):
import java.util.Arrays;
import java.util.Scanner;

public class ThreeStrings {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int t= sc.nextInt();
        for (int i = 0; i < t; i++) {
            String a = sc.next();
            String b = sc.next();
            String c = sc.next();

            int lenA = a.length();
            int lenB = b.length();
            int lenC = c.length();

            long dp[][] = new long[lenA + 10][lenB + 10];

            for(long [] x : dp ) Arrays.fill( x , -1 );

            System.out.println(rec( 0 , 0 , dp , lenA , lenB , a , b, c));
        }
    }

    static long rec ( int x , int y , long dp[][] , int lenA , int lenB , String a , String b, String c){

        if ( x == lenA ){
            long add = 0;
            for(int i = y ; i < lenB ;i++){
                if ( b.charAt(i) != c.charAt( x + i )) add ++ ;
            }
            return add ;
        }
        if ( y == lenB ){
            long add = 0;
            for(int i = x ; i < lenA ;i++){
                if ( a.charAt(i) != c.charAt( i + y )) add ++ ;
            }
            return add ;
        }
        if ( dp[x][y] != -1) return dp[x][y];
        long ans1 = (a.charAt( x ) == c.charAt( x + y ) ? 0 : 1 ) + rec( x + 1 , y , dp , lenA , lenB , a, b, c);
        long ans2 = (b.charAt( y ) == c.charAt( x + y ) ? 0 : 1 ) + rec( x  , y + 1 , dp , lenA , lenB , a, b, c);

        return dp[x][y] = Math.min(ans1 , ans2);
    }
}


Solution 2 (runtime: 296 ms):
//package codeforcesques;
import java.util.*;
import java.io.*;
public class ThreeStrings {
    int mincount = Integer.MAX_VALUE;

    public static void main(String[] args) {
        FastReader fs = new FastReader();

        int t = fs.nextInt();

        while (t-- > 0) {
            String s1 = fs.nextLine();
            String s2 = fs.nextLine();
            String s3 = fs.nextLine();
            ThreeStrings d = new ThreeStrings();
            int[][] dp = new int[s1.length()][s2.length()];
            for (int i = 0; i < s1.length(); i++) {
                Arrays.fill(dp[i], -1);
            }
            System.out.println( s3.length()-rec(0, 0, 0, s1, s2, s3, dp));
        }
    }
    public static int rec(int n, int i, int j, String a, String b, String c, int[][] dp) {
        if (i == a.length()) {
            int val = 0;
            while (j < b.length()) {
                if (b.charAt(j) == c.charAt(n)) {
                    val++;
                }
                j++;
                n++;
            }
            return val;
        }
        if (j == b.length()) {
            int val = 0;
            while (i < a.length()) {
                if (a.charAt(i) == c.charAt(n)) {
                    val++;
                }
                i++;
                n++;
            }
            return val;
        }
        if (dp[i][j] != -1) {
            return dp[i][j];
        }
        int c1 = 0;
        int c2 = 0;
        if (a.charAt(i) == c.charAt(n)) {
            c1++;
        }
        if (b.charAt(j) == c.charAt(n)) {
            c2++;
        }
        int max1 = rec(n + 1, i + 1, j, a, b, c, dp) + c1;
        int max2 = rec(n + 1, i, j + 1, a, b, c, dp) + c2;
        dp[i][j] = Math.max(max1, max2);
        return dp[i][j];
    }
}
class FastReader {
    BufferedReader gt;
    StringTokenizer st;

    public FastReader() {
        gt = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(gt.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    String nextLine() {
        String str = "";
        try {
            str = gt.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    int[] readIntArray(int n) {
        int[] res = new int[n];
        for (int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    long[] readLongArray(int n) {
        long[] res = new long[n];
        for (int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }

    String[] readStringArray(int n) {
        String[] str = new String[n];
        for (int i = 0; i < n; i++)
            str[i] = nextLine();

        return str;
    }

    int getGCD(int a, int b) {
        if (b == 0)
            return a;
        else
            return getGCD(b, a % b);
    }
}