let catalan n =
  let dp = Array.make (n + 1) 0 in
  dp.(0) <- 1;
  for i = 1 to n do
    for j = 0 to i - 1 do
      dp.(i) <- dp.(i) + dp.(j) * dp.(i - 1 - j)
    done
  done;
  dp.(n)

;;

catalan 5
