first, make full use of your own recursive algorithm thoughtRecursive algorithm can fully tap its own potential, no matter what problems encountered, it will directly or indirectly call its own algorithm to solve. The principle of recursive algorithm thought is that there is something to ask for. Even if it is difficult to solve the solution also to solve their own, even if it is difficult to solve the tough to solve. Recursive algorithm is often used in the form of functions, so recursive algorithms need to write functional functions, these functions are independent functions, to achieve the specific function of solving a problem, when needed to call the function directly.
1, the basis of recursive algorithmIn the computer programming application, the recursive algorithm is very effective to solve most problems, she can make the description of the algorithm and easy to understand, recursive algorithm has the following 3 features: (1) The recursive process is generally implemented by functions or sub-processes. (2) Recursive algorithm calls its own algorithm either directly or briefly in the interior of a function or sub-procedure. (3) The recursive algorithm is actually a sub-problem that transforms the problem into a scaled-down homogeneous problem, and then recursively invokes the function or procedure to represent the solution of the problem.
2, when using recursive algorithm, note a few points &NBSP ; , &NB Sp , &NB Sp , &NB Sp , &NB Sp , &NB Sp , &NB Sp /   / (1) recursion is the process of invoking itself in a procedure or function
(2) When using a recursive strategy, there must be a definite recursive end condition, which is referred to as a recursive exit.
(3) Recursive algorithm is usually very concise, but inefficient operation, so generally do not advocate the use of recursive algorithm design program.
(4) During recursive invocation, the system uses stacks to store the return points and local variables for each layer. If recursion is too many, it is easy to cause stack overflow, so the recursive algorithm is generally not advocated to design the program. 3, example----------Hanoi tower problem:
There are three pillars in a temple, and the first one has 64 plates, and the plates are getting bigger and larger from the top down. Ask the old monk in the temple to move all 64 plates to the third pillar. When moving, there is always a small plate pressing on a large plate. And you can only move one at a time.
1, at this time the old monk (called the 1th Monk) he thought: If a person can move the first 63 plates to the second pillar, I then move the last plate directly to the third pillar, and then let that person to move the first 63 plates from the second column on the third pillar, my task is complete, simple. So he looked for the 2nd monk and let it:
①, you move the first 63 plates to the second pillar.
② after I put my 64th plate on the third pillar,
③, you move the first 63 plates to the third pillar.
2, the 2nd Monk after the mission and the 1th monk like: if there is a person can put the first 62 plates to move to the third pillar, I then the last plate to move directly to the second pillar, and then let the person put the first 62 plates from the third pillar moved to the third pillar, my task is completed, So he also looked for a younger monk than him to call him the 3rd monk and let it:
①, you move the first 62 plates to the third pillar.
②, after I put my 63rd plate on the second pillar,
③, you move the first 62 plates to the second pillar.
3, the 3rd monk took the task, and the task of moving the first 61 plates of gourd words to the next scoop to the 4th monk, and so on, until the task handed to the 64th monk (estimated 64th a monk is depressed, no chance also ordered others, because to him here the plate has only one).
4, to the completion of this task, to the completion of their respective duties. Complete the push back:
The 64th monk moves the 1th plate, moves it away, and the 63rd monk moves the 2nd plate he assigns to himself. The 64th Monk then moved the 1th plate to the 2nd plate. By the completion of the 64th Monk's mission, the 63rd Monk completed the first step of the 62nd Monk's assignment to him.
As can be seen from the above, only the 64th Monk's task is completed, the 63rd Monk's task can be completed, only 2nd Monk task completed, 1th Monk's task can be completed. This is a typical recursive problem.
/**************************************************************************************************************
* Document Description:
* Fibonacci Series Implementation
* Development environment:
* win10+vs2015+opencv3.2.0
* Time and place:
* Shaanxi Normal University. Wen Jin Lou 2017.6.10
* Author information:
* Sir Lee
**************************************************** /
#include <stdio.h>
# include<windows.h>
int main ()
{
void hanoi (int n,char One,char Two,char three);
int m;
printf ("Input the number of diskes:");
scanf_s ("%d", &m);
printf ("The Step to move%d diskes:\n", m);
Hanoi (M, ' A ', ' B ', ' C ');
System ("pause");
return 0;
}
void Hanoi (int n, char One, Char two, char three)//move n plates from one seat to the three block
{
void Move (char x, char y) with two seats;
if (n = = 1)
move (one, three);
else
{
Hanoi (n-1, one, three, and both);
Move (One,three);
Hanoi (N-1,two, one, three);
}
}
void Move (char x, char y)
{
printf ("%c--->%c\n", x, y);
}
, &NB Sp &NBS P , &NB Sp , &NB Sp , &NB Sp , &NB Sp , &NB Sp