uk-coins的运行时间较长
(define (cc amount coin-values)
(cond ((= amount 0) 1)
((or (< amount 0) (no-more? coin-values)) 0)
(else
(+ (cc amount
(except-first-denomination coin-values))
(cc (- amount (first-denomination coin-values))
coin-values)))))
(define no-more? null?)
(define except-first-denomination cdr)
(define first-denomination car)
(define us-coins '(50 25 10 5 1))
(define uk-coins '(100 50 20 10 5 2 1 0.5))
(newline)
(display (cc 100 us-coins))
(newline)
(display (cc 100 uk-coins))
本文展示了一个使用Scheme语言定义的递归过程来计算给定金额下特定硬币组合的数量的方法。通过对比美国和英国硬币系统的示例,演示了如何通过程序实现这一计算。
2925

被折叠的 条评论
为什么被折叠?



