Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn find-best-combination
- [dolls-information weight-restriction index]
- (if (zero? weight-restriction)
- [0 []]
- ;else
- (if (< index 0)
- [0 []]
- ;else
- (let [{doll-weight :weight doll-value :value} (get dolls-information index)]
- (if (> doll-weight weight-restriction)
- (find-best-combination-memoized dolls-information weight-restriction (- index 1))
- ;else
- (let [[vn sn :as no] (find-best-combination-memoized dolls-information weight-restriction (- index 1))
- [vy sy :as yes] (find-best-combination-memoized dolls-information (- weight-restriction doll-weight) (- index 1))]
- (if (> (+ vy doll-value) vn)
- [(+ vy doll-value) (conj sy index)]
- ;else
- no
- )
- )
- )
- )
- )
- )
- )
Add Comment
Please, Sign In to add comment