说明:在学习算法导论,需要写一嵌套的小程序,题目是:
Consider a three-parameter recursive function w(a, b, c):
if a <= 0 or b <= 0 or c <= 0, then w(a, b, c) returns: 1
if a > 20 or b > 20 or c > 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) 。
直接上我写的代码啦:
int function_recursion::Implement_recursion(int ,int,int) { int i, j; for (i = 0; i < sample_num; i++) { if (TriplsSries[i][0] <= 0 || TriplsSries[i][1] <= 0 || TriplsSries[i][2]<=0) Implement_recursion(TriplsSries[i][0], TriplsSries[i][1], TriplsSries[i][2]) = 1; } }
说明下:TriplsSries是输入的(a,b,c)样本集存到二元数组TriplsSries[i][j]中,但是出现如题的Bug:”Implement_recursion(TriplsSries[i][0], TriplsSries[i][1], TriplsSries[i][2]) = 1;“这一行提示错误为:表达式必须是可修改的左值。
各位大神,你们错误出现在哪儿吗?(先写完完整的程序,再给出我自己的解决方案,O(∩_∩)O)
时间: 2024-10-29 19:06:49