public boolean solution(String s1, String s2, String s3, int i, int j, int k) {
        if (k == s3.length()) {
            return true;
        }
        if (matrix[i][j] != 0) {
            return matrix[i][j] == 1; 
        }
        boolean result = false;
        if (i < s1.length() && s1.charAt(i) == s3.charAt(k)) {
            result = result || solution(s1, s2, s3, i + 1, j, k + 1);
        }
        if (j < s2.length() && s2.charAt(j) == s3.charAt(k)) {
            result = result || solution(s1, s2, s3, i, j + 1, k + 1);
        }
        matrix[i][j] = result ? 1 : -1;
        return result;
    }