Skip to content

Instantly share code, notes, and snippets.

@murasesyuka
Last active March 9, 2017 22:49
Show Gist options
  • Select an option

  • Save murasesyuka/d1a156fc97d13d104d4dc45d24c4ff94 to your computer and use it in GitHub Desktop.

Select an option

Save murasesyuka/d1a156fc97d13d104d4dc45d24c4ff94 to your computer and use it in GitHub Desktop.
Successfully set matrix of OCaml
module DP =
struct
let h = 13
let w = 17
(* let memo = Array.make (h+1) (Array.make (w+1) 0) *)
let memo = Array.make_matrix (h+1) (w+1) 0
let rec dfs nowh noww =
if nowh > h || noww > w then
0
else if nowh = h && noww = w then
1
else if memo.(nowh).(noww) <> 0 then memo.(nowh).(noww)
else begin
memo.(nowh).(noww) <- ((dfs (nowh+1) noww) + (dfs nowh (noww+1)));
memo.(nowh).(noww)
end
end
let () = Printf.printf "hello %d" (DP.dfs 0 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment