let coin_change coins target = let dp = Array.make (target + 1) (target + 1) in dp.(0) <- 0; for i = 1 to target do List.iter (fun c -> if c <= i && dp.(i - c) + 1 < dp.(i) then dp.(i) <- dp.(i - c) + 1 ) coins done; if dp.(target) > target then -1 else dp.(target) ;; coin_change [1; 5; 10; 25] 67