`
Bloodwolf
  • 浏览: 88805 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

sicp 1.14

    博客分类:
  • SICP
 
阅读更多

如下过程:

 

(define (count-change amount)
  (cc amount 5))

(define (cc amount kinds-of-coins)
  (cond ((= amount 0) 1)
		((or (< amount 0) (= kinds-of-coins 0)) 0)
		(else (+ (cc amount (- kinds-of-coins 1))
				 (cc (- amount (first-denomination kinds-of-coins)) kinds-of-coins)))))

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

 

(count-change 11)计算过程:

(cc 11 5) = (cc 11 4) + (cc -39 5)

                = (cc 11 3) + (cc -14 4)

                = (cc 11 2) + (cc 1 3)

                = (cc 11 1) + (cc 6 2) + (cc 1 2) + (cc -9 3)

                = (cc 11 0) + (cc 10 1) + (cc 6 1) + (cc 1 1) + (cc 1 1) + (cc -4 2)

                = (cc 10 0) + (cc 9 1) + (cc 6 0) + (cc 5 1) + (cc 1 0) + (cc 0 1) + (cc 1 0) + (cc 0 1)

                = (cc 9 0) + (cc 8 1) + (cc 5 0) + (cc 4 1) + 1 + 1

                = (cc 8 0) + (cc 7 1) + (cc 4 0) + (cc 3 1) + 1 + 1

                = ...

                = 1 + 1 + 1 + 1

                = 4

 

可以看出,时间空间都是线性增长。

分享到:
评论

相关推荐

    SICP中文第二版

    SICP中文第二版SICP中文第二版SICP中文第二版SICP中文第二版SICP中文第二版

    sicp in python 中文 sicp 中文

    sicp in python 中文版 sicp in python 中文版 sicp in python 中文版 !!!download&gt;&gt;&gt;https://github.com/wizardforcel/sicp-py-zh

    SICP(python中文带书签)

    《计算机程序的构造与解释》(Structure and Interpretation of Computer Programs,简称SICP)是一本备受推崇的经典计算机科学教材,由Harold Abelson和Gerald Jay Sussman撰写,并由MIT出版社出版。这本书以其深入...

    sicp 2.2.4节图形语言

    《SICP 2.2.4 节:图形语言》是计算机科学经典教材《结构与解释程序》(Structure and Interpretation of Computer Programs)中的一个重要章节,它深入介绍了如何利用编程来创建图形,以及如何设计和理解复杂的计算...

    SICP 解题集

    《SICP解题集》是一份专注于探讨和解答《结构与解释程序》(Structure and Interpretation of Computer Programs,简称SICP)一书中习题的资源。SICP是计算机科学领域的一本经典教材,由Harold Abelson、Gerald Jay ...

    SICP 习题答案

    《计算机程序的构造和解释》(SICP)是一本极具影响力的计算机科学教材,由Harold Abelson和Gerald Jay Sussman所著,MIT出版社出版。这本书以其深入探讨编程概念、程序设计方法以及计算机系统的工作原理而闻名。1-3...

    北京大学,计算机程序构造和解释(SICP)课件,裘宗燕老师主讲

    《计算机程序构造和解释》(SICP,Structure and Interpretation of Computer Programs)是一本具有深远影响力的计算机科学教材,由Harold Abelson和Gerald Jay Sussman编写,MIT Press出版。这门课程由北京大学数学...

    SICP习题解答,主要第一章的内容习题答案

    《SICP习题解答,主要第一章的内容习题答案》 SICP,全称《Structure and Interpretation of Computer Programs》(计算机程序的构造和解释),是计算机科学领域的一本经典教材,由MIT(麻省理工学院)的 Harold ...

    SICP-Python版本

    SICP-Python版本

    SICP 使用的scheme解释器

    SICP 使用的scheme解释器 以前叫DrScheme

    Python SICP epub版本

    Python SICP epub版本,很适合学习抽象的思想,用Python版本比lisp更实用

    SICP LISP AI

    《SICP》全称是《Structure and Interpretation of Computer Programs》,中文译为《计算机程序的构造和解释》。这是一本经典的计算机科学教材,由Harvard大学的 Harold Abelson 和 Gerald Jay Sussman 教授撰写,...

    PyPI 官网下载 | sicp-0.0.1b102.dev4.tar.gz

    标题中的"PyPI 官网下载 | sicp-0.0.1b102.dev4.tar.gz"指的是从Python的官方包索引(Python Package Index,简称PyPI)上下载的一个名为"sicp"的软件包的版本号为0.0.1b102.dev4的压缩文件,其格式是tar.gz。...

    a_book_sicp_py

    本书名为《a_book_sicp_py》,是一本以Python语言为基础介绍设计模式和计算机科学基础的书籍。根据描述和部分内容,可以提炼出以下知识点: 1. 编程语言的重要性:在计算机科学的宽泛领域中,编程语言扮演着至关...

    sicp in python 中文版 sicp

    sicp in python 中文版 sicp in python 中文版 sicp in python 中文版 download : https://github.com/wizardforcel/sicp-py-zh

    sicp 2nd 英文chm

    《Structure and Interpretation of Computer Programs》(简称SICP)是计算机科学领域的一部经典教材,由Harold Abelson和Gerald Jay Sussman撰写,第二版(2nd Edition)通常被称为SICP 2nd。这本书是麻省理工学院...

    sicp-in-python(中文版+英文版)PD

    sicp-in-python(中文版+英文版)PDF 背景. SICP 全称Structure and Interpretation of Computer Programs,翻译过来叫《计算机程序的构造和解释》使用python

    sicp第二章练习题的解答

    《SICP(Structure and Interpretation of Computer Programs)》是一本经典的计算机科学教材,由Harold Abelson和Gerald Jay Sussman所著,它强调了程序设计的基础和原理,特别是函数式编程思想。第二章主要探讨了...

    SICP:SICP解决方案

    《SICP:SICP解决方案》是针对结构与解释程序设计(Structure and Interpretation of Computer Programs,简称SICP)这本书的详细解答和实践指南。SICP是一本经典的计算机科学教材,由Harold Abelson和Gerald Jay ...

Global site tag (gtag.js) - Google Analytics