先上代码吧。
(defn first-denomination [coin-values]
(first coin-values)
)
(defn no-more? [coin-values]
(if (empty? coin-values) true
false
)
)
(defn except-first-denomination [coin-values ]
(rest coin-values )
)
(defn cc[amount coin-values]
(cond (= amount 0) 1
(or (< amount 0) (no-more? coin-values)) 0
:esle (+ (cc amount (except-first-denomination coin-values))
(cc (- amount (first-denomination coin-values)) coin-values)
)
)
)
(def us-coins (list 50 25 10 5 1))
执行结果如下
不会影响,相当于求排列组合,元素的起始顺序,并不能影响排列组合组数。随机调整顺序后,执行结果如下。