algorithms

Algorithm implementations
git clone git://git.laack.co/algorithms.git
Log | Files | Refs | README

main.ml (629B)


      1 let readInt () = Scanf.scanf " %d" (fun x -> x) in
      2 let rec solve arr idx a b c =
      3     if idx >= Array.length arr then
      4         if idx > Array.length arr then -1000000000 else 0
      5     else
      6         if arr.(idx) <> -1 then arr.(idx) else
      7             let aA = 1 + solve arr (idx+a) a b c in
      8             let aB = 1 + solve arr (idx+b) a b c in
      9             let aC = 1 + solve arr (idx+c) a b c in
     10                 let mx = max (max aA aB) aC in
     11                     arr.(idx) <- mx; mx
     12 in
     13 let n = readInt () in let a = readInt () in let b = readInt () in let c = readInt () in
     14 print_int (solve (Array.make n (-1)) 0 a b c); print_newline ()