这道英文的计算机算法讲的究竟是什么意思?3QWe 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,
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/23 21:26:07
这道英文的计算机算法讲的究竟是什么意思?3QWe 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,
这道英文的计算机算法讲的究竟是什么意思?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.
这道英文的计算机算法讲的究竟是什么意思?3QWe 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,
中间是不是有一段话你没有复制上来呢.前面就是说了一个递归函数,然后说直接实现这个递归会很慢. 下面就说,你需要写用上面的方法(这个“上面的方法”在哪里?上面明明只定义了递归函数.)写一个程序来有效的计算这个递归函数