let count_subseq s t =
  let m = String.length s in
  let n = String.length t in
  let dp = Array.init (m + 1) (fun _ -> Array.make (n + 1) 0) in
  for i = 0 to m do
    dp.(i).(0) <- 1
  done;
  for i = 1 to m do
    for j = 1 to n do
      if s.[i - 1] = t.[j - 1] then
        dp.(i).(j) <- dp.(i - 1).(j) + dp.(i - 1).(j - 1)
      else
        dp.(i).(j) <- dp.(i - 1).(j)
    done
  done;
  dp.(m).(n)

;;

count_subseq "rabbbit" "rabbit"
