c语言递归详细解答(C language recursive detailed answer)Erudite, questioning, deliberative, discernment, and faithful. It is the southern landscape, end of spring again. Alone, body and shadow comforting each other. Cai Feng Shuangfei body without wings, heart to heart. Ruthless is not really heroic, pity son how not husband?. recursionRecursion is a powerful tool for designing and describing algorithms, as it is often used in the description of complex algorithms, and for this reason, it is discussed before further introducing other algorithms.Can the recursive algorithms described usually has such features: in order to solve the problem of size N, try to break it down into smaller problems, and then from these small solutions facilitate the construction of a big problem solution, and these smaller problems can also use the same decomposition and synthesis method, decomposition the smaller problems, and from the deconstruction of create larger scale problems in solving these problems less. In particular, when the scale is N=1, it can be solved directly.[PROBLEMS] written to calculate Fibonacci (Fibonacci) n function FIB sequence (n).Fibonacci Numbers: 0, 1, 1, 2, 3,...... Namely:FIB (0) =0;FIB (1) =1;FIB (n), =fib (n-1), +fib (n-2) (when n>1).Recursive function:Int FIB (int n){if (n==0) return 0;If (n==1) return 1;If (n>1), return, FIB (n-1), +fib (n-2);}The execution process of recursive algorithm is divided into two stages: recursion and regression. In the recursive stage, the solution of the complex problem (scale n) is simplified to a simpler problem than that of the original problem (size less than n). For example, in this case, for FIB (n), pushing it to the solution of FIB (n-1) and FIB (n-2). That is to say, in order to compute FIB (n), you must first compute FIB (n-1) and FIB (n-2), while FIB (n-1) and FIB (n-2) must be computed first, and then FIB (n-3) and FIB (n-4) must be computed first. By analogy, and 1 (0) can be obtained immediately after the calculations FIB (1) and FIB (0), respectively. In the recursive phase, there must be termination of recursion. For example, in function FIB, when n is 1 and 0.In the regression stage, when the solution of the simplest case is obtained, the problem is returned gradually, and the solution of a slightly complex problem is obtained. For example,after obtaining FIB (1) and FIB (0), the result of FIB (2) is returned,...... After getting the results of FIB (n-1) and FIB (n-2), return the result of FIB (n).Should pay attention to in the preparation of a recursive function, local variables and parameters of the knowledge function is limited to the current call layer, when recursive into "simple" layer, the original level of the parameters and local variables will be hidden. In a series of "simple problem" layers, they each have their own parameters and local variables.Since recursion results in a series of function calls and may have a series of repeated computations, the execution efficiency of the recursive algorithm is relatively low. When a recursive algorithm can be conveniently converted to recursive algorithm, it is usually written by recursive calculation method. For example, calculated the Fibonacci sequence in n function FIB (n) using recursive algorithm, namely from the top two of the Fibonacci sequence, successive two calculated by the former one, until the calculated requirements of section n.[problem] combinatorial problemProblem Description: find out from natural numbers 1 and 2,...... N, any combination of R numbers. For example, all combinations of n=5 and r=3 are: (1) 5, 4, 3 (2), 5, 4, 2 (3), 5, 4, 1(4) 5, 3, 2 (5), 5, 3, 1 (6), 5, 2,, and 1(7) 4, 3, 2 (8), 4, 3, 1 (9), 4, 2,, and 1(10) 3, 2, 1Analysis of the 10 combinations, you can use this recursive thinking to consider the algorithm to find the combination function. Set the function to void comb (int, m, int, K) to find out from the natural numbers 1, 2,...... M, any combination of K numbers. When the first number of the combination is timed, the subsequent number is the combination of the k-1 numbers from the remaining M-1 numbers. This will find the combination of K numbers in the number of M, the problem is converted into M-1 numbers in order to take the combination of k-1 numbers. A work function into an array of a[] obtained the combination of digital storage, agreed function will identify K digital first digital combination on the a[k], when a combination was obtained, it will be a combination of output in a[]. The first number can be m, m-1,...... K function will determine the first combination of numbers into an array, there are two possible choices for the remaining elements also did not go to the top combination, continue to identify recursive or because have been identified; all the elements, the output of the combination. For details see the function comb in the following program.【程序】#包括< stdio. h >#定义maxn演100a [ maxn演];空梳子(整数M,int K){ int i,j;对于(i = m;i = k;i -){;如果(k>1)梳子(i-1,k-1);其他的{(j = A [ 0 ];j>0;j -)printf(“4D”,一个[ J ]);printf(“\n”);}}}无效main(){ [ 0 ]=3;梳子(5,3);}【问题】背包问题问题描述:有不同价值、不同重量的物品N件,求从这N件物品中选取一部分物品的选择方案,使选中物品的总重量不超过指定的限制重量,但选中物品的价值之和最大。