let count_ways coins target =
  let dp = Array.make (target + 1) 0 in
  dp.(0) <- 1;
  List.iter (fun c ->
    for i = c to target do
      dp.(i) <- dp.(i) + dp.(i - c)
    done
  ) coins;
  dp.(target)

;;

count_ways [1; 2; 5; 10; 25] 50
