Title: Classical Questions: 3 months from the month of a pair of rabbits, the rabbit long to the third month after the birth of a pair of rabbits each month, if the rabbit is not dead, ask the number of rabbits each month for how much?
Analysis: First of all, we need to understand the meaning of the topic refers to the total logarithm of the rabbit every month; if the rabbit is divided into small and middle three species, rabbits will produce a pair of rabbits every month after three months of birth,
Then we assume that the first month of the rabbit as a small rabbit, the second month for the Rabbit, the third month after the Big Rabbit, then the first month, there are 1, 0, 0, the second month are 0, 1, 0,
The third month were 1, 0, 1, fourth month respectively, 1, 1, 1, fifth month respectively 2, 1, 2, sixth month respectively 3, 2, 3, seventh month respectively 5, 3, 5 ...
The total number of rabbits were: 1, 1, 2, 3, 5, 8, 13 ...
So we have a rule that from the third month onwards, the total number of rabbits behind is equal to the total number of rabbits in the preceding two months, which is the Fibonacci sequence.
Java code:
A classic example of a recursive algorithm.
The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring some help, but also hope that a lot of support cloud Habitat community!