Recursive
1 What is recursion?: Based on the value of the existing node and the value of the node after the rule is rolled out
2 Why use recursion: a simple solution to a disciplined event
3 How to use? :
Let's give a classic example:
If 1 pairs of rabbits can produce 1 pairs of rabbits a month, and each pair of rabbits in its 3rd month after birth can produce 1 pairs of rabbits, if starting from 1 pairs of newborn rabbits, 1 years later can reproduce how many rabbits?
def my1 (max):
A, b,c, i= 1,0,0 0
While I<max:
c = c+b
b = A
A = C
Print A+b+c
I+=1
Methods: We can divide the rabbit into 1-month-old, 2-month-old, 3-month-old through the law we know that the 1-month-old rabbit will become the February Big Rabbit next month, and February will become March
Big and March will always accumulate, so the rule is very obvious, March big next month equals itself March rabbit + February Rabbit (Grow Up), and the February Rabbit will become the number of rabbits in January,
The number of January equals the March Bunny (3 months rabbit will give birth to rabbits)
Recursion of 01python algorithm