ivaneeo's blog

          自由的力量,自由的生活。

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            669 Posts :: 0 Stories :: 64 Comments :: 0 Trackbacks
          有100美元需找零.
          ??? 美元中有50美分(half-dollars),25美分(quarters),10美分(dimes),5美分(nickels),1美分(pennies).
          總共有多少種方式?

          分成兩步:
          ??? 1.計算使用50美分找零的方法數(shù).
          ??? 2.上面數(shù)目加上除了使用50美分找零的方法數(shù)以外的數(shù)目.

          (define (count-change amount)
          ? (cc amount 6))

          (define (first-denomination kinds-of-coins)
          ? (cond ((= kinds-of-coins 1) 1)
          ??? ((= kinds-of-coins 2) 2)
          ??? ((= kinds-of-coins 3) 5)
          ??? ((= kinds-of-coins 4) 10)
          ??? ((= kinds-of-coins 5) 20)
          ??? ((= kinds-of-coins 6) 50)))

          (define (cc amount kinds-of-coins)
          ? (cond ((= amount 0) 1)
          ??? ((or (< amount 0)
          ??? ??? (= kinds-of-coins 0))
          ??? ?0)
          ??? (else (+ (cc (- amount?? ?? ?? ?? ?? ?? ?? ?? ;第一步
          ??? ??? ??? (first-denomination kinds-of-coins))
          ??? ??? ???? kinds-of-coins)
          ??? ??? ?(cc amount?? ?? ?? ?? ?? ?? ?? ?? ?? ??? ;第二步
          ??? ??? ???? (- kinds-of-coins 1))))))
          posted on 2006-07-30 15:51 ivaneeo 閱讀(465) 評論(0)  編輯  收藏 所屬分類: scheme-語言之母
          主站蜘蛛池模板: 商城县| 保山市| 邢台县| 甘孜| 新泰市| 海淀区| 连城县| 双流县| 隆德县| 疏附县| 浏阳市| 治县。| 岳西县| 永和县| 泾源县| 饶平县| 定结县| 湘乡市| 凤阳县| 绥中县| 通海县| 林甸县| 刚察县| 西峡县| 斗六市| 兴宁市| 报价| 舞钢市| 吴旗县| 芜湖县| 屏山县| 周至县| 交城县| 建湖县| 邹平县| 蒙山县| 芦山县| 广东省| 信阳市| 会昌县| 卢湾区|