ivaneeo's blog

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

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

          分成兩步:
          ??? 1.計(jì)算使用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) 評(píng)論(0)  編輯  收藏 所屬分類: scheme-語(yǔ)言之母
          主站蜘蛛池模板: 宣汉县| 孟村| 兰坪| 澎湖县| 红河县| 平武县| 临高县| 庄浪县| 乐陵市| 策勒县| 临猗县| 平武县| 攀枝花市| 仪征市| 丰顺县| 凭祥市| 汉川市| 开平市| 湾仔区| 阳春市| 石台县| 乌兰察布市| 盐源县| 鹤山市| 万年县| 微博| 渝中区| 高安市| 武定县| 集贤县| 三台县| 威宁| 二连浩特市| 芷江| 阿拉善左旗| 阿克苏市| 通许县| 思茅市| 姚安县| 镇安县| 香格里拉县|