Created
May 12, 2015 21:06
-
-
Save alpinskiy/ea720be10782bb89403c to your computer and use it in GitHub Desktop.
algo2-004 / Problem Set #3 / Question 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def v [0.05 0.4 0.08 0.04 0.1 0.1 0.23]) | |
(declare mm) | |
(defn m [i j] | |
(cond | |
(< i (dec j)) (letfn [(f [r] | |
(+ (reduce + (subvec v i j)) | |
(mm i r) | |
(mm (inc r) j)))] | |
(apply min (map f (range i j)))) | |
(= i (dec j)) (v i) | |
:else 0)) | |
(def mm (memoize m)) | |
(println (m 0 (count v))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment