首页 > 其他分享 >sicp每日一题[2.43]

sicp每日一题[2.43]

时间:2024-10-13 08:52:48浏览次数:1  
标签:2.42 2.43 Louis 每日 sicp program board queens size

Exercise 2.43

Louis Reasoner is having a terrible time doing Exercise 2.42. His queens procedure seems to work, but it runs extremely slowly. (Louis never does manage to wait long enough for it to solve even the 6 × 6 case.) When Louis asks Eva Lu Ator for help, she points out that he has interchanged the order of the nested mappings in the flatmap, writing it as

(flatmap
 (lambda (new-row)
   (map (lambda (rest-of-queens)
          (adjoin-position new-row k rest-of-queens))
        (queen-cols (- k 1))))
 (enumerate-interval 1 board-size))

Explain why this interchange makes the program run slowly. Estimate how long it will take Louis’s program to solve theeight-queens puzzle, assuming that the program in Exercise 2.42 solves the puzzle in time T.


慢的原因比较好理解,Louis 的答案每一次都要把 queen-cols 计算 (enumerate-interval 1 board-size) 遍,一共算了 board-size^board-size 遍,对于八皇后问题就是 8^8 遍;对于练习 2.42 的原方法,每次循环都会减一次,所以一共计算了 n! 次,如果原方法时间为 T,那么 Louis 的方法要用的时间是 8^8/8!*T.

标签:2.42,2.43,Louis,每日,sicp,program,board,queens,size
From: https://www.cnblogs.com/think2times/p/18461838

相关文章

  • 每日OJ题_牛客_比那名居的桃子_滑动窗口/前缀和_C++_Java
    目录牛客_比那名居的桃子_滑动窗口/前缀和题目解析C++代码Java代码牛客_比那名居的桃子_滑动窗口/前缀和比那名居的桃子(nowcoder.com)描述:        小红有一天看到了一只桃子,由于桃子看上去就很好吃,小红很想把它吃掉。已知吃下桃子后,每天可以获得ai​的......
  • 每日读则推(八)——Alice Weidel‘s speech
    Whogaveyouthepowertogivethepeople'shard-earnedmoneytoeconomicrefugees                                       n.辛苦钱,血汗钱              ......
  • 每日一歌歌词
    2024.10.13《Reignite》官方MV:BV11F411g7HoReignite-EchoLab作词:黑金雨作曲:EchoLab音乐制作人:胡臻混音:HARUOSAITOH(THERMALMIX)吉他:並木瑠璃弦乐编写:松田純一人声录音:31Studio音乐监制:陈瑶/聂婉迪(EchoLab)监制:魔奇工作室把少年......
  • 万字详解AI实践,零手写编码用AI完成开发 + 数据清洗 + 数据处理 的每日新闻推荐,带你快
    用AI+dify完成前后端开发+数据处理和数据清洗。引言数据获取和数据处理dify构建workflow进行数据清洗前端页面构建和前后端交互总结引言AI时代对开发人员的加强是非常明显的,一个开发人员可以依靠AI横跨数个自己不熟悉的领域包括前后端、算法等。让我们来做个实践,全程......
  • 微信公众号推送每日天气(Java版)
    准备工作公众号必须经过企业认证,个人公众号的无法使用这是获取到微信公众号的appId、secret网址贴这儿了:https://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index还有测试的模板申请每日一言,我这里使用的彩虹屁,地址:https://www.tianapi.com/......
  • sicp每日一题[2.42]
    这道题太难了,我自己只完成了empty-board这一个定义,其他的函数即使看了别人的答案也研究了半天才搞明白。。;board-size指的是正方形棋盘的长(define(queensboard-size)(define(queen-colsk)(if(=k0)(listempty-board)(filter......
  • 每日算法 88.合并两个有序数组 - Lcode
    给你两个按 非递减顺序 排列的整数数组 nums1 和 nums2,另有两个整数 m 和 n ,分别表示 nums1 和 nums2 中的元素数目。请你 合并 nums2 到 nums1 中,使合并后的数组同样按 非递减顺序 排列。注意:最终,合并后数组不应由函数返回,而是存储在数组 nums1 中。为了......
  • sicp每日一题[2.40]
    Exercise2.40Defineaprocedureunique-pairsthat,givenanintegern,generatesthesequenceofpairs(i,j)with1<j<i<n.Useunique-pairstosimplifythedefinitionofprime-sum-pairsgivenabove.这道题还是挺简单的,最难的部分书上已经实现了,我们只......
  • sicp每日一题[2.38-2.39]
    Exercise2.38Theaccumulateprocedureisalsoknownasfold-right,becauseitcombinesthefirstelementofthesequencewiththeresultofcombiningalltheelementstotheright.Thereisalsoafold-left,whichissimilartofold-right,exceptthati......
  • Python 工具库每日推荐【openpyxl 】
    文章目录引言PythonExcel处理库的重要性今日推荐:openpyxl工具库主要功能:使用场景:安装与配置快速上手示例代码代码解释实际应用案例案例:自动生成月度销售报告案例分析高级特性条件格式数据验证扩展阅读与资源优缺点分析优点:缺......