早教吧作业答案频道 -->英语-->
这道英文的计算机算法讲的究竟是什么意思?3QWeallloverecursion!Don'twe?Considerathree-parameterrecursivefunctionw(a,b,c):ifa20,thenw(a,b,c)returns:w(20,20,20)ifa
题目详情
这道英文的计算机算法讲的究竟是什么意思?3Q
We all love recursion!Don't we?Consider a three-parameter recursive function w(a,b,c):if a 20,then w(a,b,c) returns:w(20,20,20) if a < b and b < c,then w(a,b,c) returns:w(a,b,c-1) + w(a,b-1,c-1) - w(a,b-1,c) otherwise it returns:w(a-1,b,c) + w(a-1,b-1,c) + w(a-1,b,c-1) - w(a-1,b-1,c-1) This is an easy function to implement.The problem is,if implemented directly,for moderate values of a,b and c (for example,a = 15,b = 15,c = 15),the program takes hours to run because of the massive recursion.Input The input for your program will be a series of integer triples,one per line,until the end-of-file flag of -1 -1 -1.Using the above technique,you are to calculate w(a,b,c) efficiently and print the result.Output Print the value for w(a,b,c) for each triple.
We all love recursion!Don't we?Consider a three-parameter recursive function w(a,b,c):if a 20,then w(a,b,c) returns:w(20,20,20) if a < b and b < c,then w(a,b,c) returns:w(a,b,c-1) + w(a,b-1,c-1) - w(a,b-1,c) otherwise it returns:w(a-1,b,c) + w(a-1,b-1,c) + w(a-1,b,c-1) - w(a-1,b-1,c-1) This is an easy function to implement.The problem is,if implemented directly,for moderate values of a,b and c (for example,a = 15,b = 15,c = 15),the program takes hours to run because of the massive recursion.Input The input for your program will be a series of integer triples,one per line,until the end-of-file flag of -1 -1 -1.Using the above technique,you are to calculate w(a,b,c) efficiently and print the result.Output Print the value for w(a,b,c) for each triple.
▼优质解答
答案和解析
中间是不是有一段话你没有复制上来呢.前面就是说了一个递归函数,然后说直接实现这个递归会很慢. 下面就说,你需要写用上面的方法(这个“上面的方法”在哪里?上面明明只定义了递归函数.)写一个程序来有效的计算这个递归函数
看了 这道英文的计算机算法讲的究竟...的网友还看了以下:
小燕有20本儿童读物,比小英少20%,小英有多少本儿童读物?正确的列式是()A.20×20%B.2 2020-05-22 …
加油站20升标准罐试题20升标定刻度45.7颈分度为2.5ml对加油机进行效验加油机付油20.01 2020-07-04 …
英语翻译事由:缝纫机本公司是拉哥斯最大的缝纫机进口商之一,我们经营各种牌号的缝纫机已有20余年了. 2020-07-19 …
Vb随机生成20个大写英文字母和数字(一共20个),每五个加一个连字符如题. 2020-07-23 …
小燕有20本儿童读物,比小英少20%,小英有多少本儿童读物?正确的列式是[]A.20×20%B.2 2020-07-26 …
某高职院校进行自主招生文化素质考试,考试内容为语文、数学、英语三科,总分为200分,现从上线的考生中 2020-11-06 …
阅读短文,回答问题:如图是中国第5代歼击机歼-20原型机,该飞机是具有完全独立知识产权的新型战斗机. 2020-12-04 …
材料一:2012年7月9日,海南省委、省政府隆重举行“6•29”反劫机英雄机组表彰大会,号召全省人民 2020-12-05 …
只列式不计算(1)用160的20%与112的倒数差去除16个34,商是多少?(34×16)÷(160 2020-12-08 …
英语翻译1飞机几点起飞?/几点降落?2火车几点发车?/几点到站?3飞机将在20分钟后起飞/降落4火车 2020-12-23 …