title: Count Distinct Occurrences As A Subsequence
signature: function count_distinct_occurrences_as_a_subsequence(s, t)
source_py: def count_distinct_occurrences_as_a_subsequence(S, T):
      m = len(T)
      n = len(S)
      if (m > n):
          return 0
      mat = [[0 for _ in range((n + 1))] for __ in range((m + 1))]
      for i in range(1, (m + 1)):
          mat[i][0] = 0
      for j in range((n + 1)):
          mat[0][j] = 1
      for i in range(1, (m + 1)):
          for j in range(1, (n + 1)):
              if (T[(i - 1)] != S[(j - 1)]):
                  mat[i][j] = mat[i][(j - 1)]
              else:
                  mat[i][j] = (mat[i][(j - 1)] + mat[(i - 1)][(j - 1)])
      return mat[m][n]
source_cpp: int count_distinct_occurrences_as_a_subsequence(string S, string T) {
    int m = T . length ( ), n = S . length ( );
    if ( m > n ) return 0;
    int mat [ m + 1 ] [ n + 1 ];
    for ( int i = 1;
    i <= m;
    i ++ ) mat [ i ] [ 0 ] = 0;
    for ( int j = 0;
    j <= n;
    j ++ ) mat [ 0 ] [ j ] = 1;
    for ( int i = 1;
    i <= m;
    i ++ ) {
      for ( int j = 1;
      j <= n;
      j ++ ) {
        if ( T [ i - 1 ] != S [ j - 1 ] ) mat [ i ] [ j ] = mat [ i ] [ j - 1 ];
        else mat [ i ] [ j ] = mat [ i ] [ j - 1 ] + mat [ i - 1 ] [ j - 1 ];
      }
    }
    return mat [ m ] [ n ];
  }
question_info.entry_fn_name: count_distinct_occurrences_as_a_subsequence
question_info.entry_cls_name: Solution
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(s, t, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(s, t) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver("banana", "ban", 3)
      print(string.format("TEST-0...%s",result))
  
      result = driver("49597223", "42", 2)
      print(string.format("TEST-1...%s",result))
  
      result = driver("1000010000011", "010", 20)
      print(string.format("TEST-2...%s",result))
  
      result = driver("BTlzufK", "EpsVuzP lf", 0)
      print(string.format("TEST-3...%s",result))
  
      result = driver("3474007", "370", 2)
      print(string.format("TEST-4...%s",result))
  
      result = driver("0010", "00000", 0)
      print(string.format("TEST-5...%s",result))
  
      result = driver("dKHhoTD", "doT", 1)
      print(string.format("TEST-6...%s",result))
  
      result = driver("9123259723", "123", 4)
      print(string.format("TEST-7...%s",result))
  
      result = driver("11001000111110", "0", 6)
      print(string.format("TEST-8...%s",result))
  
      result = driver("iY WJlIZ", "iI", 1)
      print(string.format("TEST-9...%s",result))
  
  end
  
  main()
question_info.test_list: [{"idx": 0, "outputs": 3, "inputs": {"s": "banana", "t": "ban"}}, {"idx": 1, "outputs": 2, "inputs": {"s": "49597223", "t": "42"}}, {"idx": 2, "outputs": 20, "inputs": {"s": "1000010000011", "t": "010"}}, {"idx": 3, "outputs": 0, "inputs": {"s": "BTlzufK", "t": "EpsVuzP lf"}}, {"idx": 4, "outputs": 2, "inputs": {"s": "3474007", "t": "370"}}, {"idx": 5, "outputs": 0, "inputs": {"s": "0010", "t": "00000"}}, {"idx": 6, "outputs": 1, "inputs": {"s": "dKHhoTD", "t": "doT"}}, {"idx": 7, "outputs": 4, "inputs": {"s": "9123259723", "t": "123"}}, {"idx": 8, "outputs": 6, "inputs": {"s": "11001000111110", "t": "0"}}, {"idx": 9, "outputs": 1, "inputs": {"s": "iY WJlIZ", "t": "iI"}}]