Title: Classical question: From 3 months to 1 month, a pair of rabbits will be born every month. After the little rabbit grows to the third month, another pair of rabbits will be born every month. If the rabbits do not die, what is the total number of rabbits each month?
Analysis: First of all, we need to understand that the meaning of the question refers to the total logarithm of rabbits in each month; assuming that rabbits are divided into three types, small, medium and large, rabbits will give birth to a pair of rabbits every month after birth.
Then we assume that the rabbit in the first month is a small rabbit, the middle rabbit in the second month, and the big rabbit after the third month, then the first month is 1, 0, and 0, respectively, and the second month is 0, 1, and 0, respectively.
The third month is 1, 0 and 1, the fourth month is 1, 1 and 1, the fifth month is 2, 1 and 2, 2, the sixth month is 3, 2 and 3, and the seventh month is 5, 3 and 5...
The total number of rabbits is: 1, 1, 2, 3, 5, 8, 13...
So a rule is drawn that from the third month, the total number of rabbits in the latter part is equal to the sum of the total number of rabbits in the first two months, which is the Fibonacci sequence.
Java code:
A very classic example of a recursive algorithm.
The above is all the content of this article. I hope that the content of this article will be of some help to everyone’s study or work. I also hope to support Wulin.com more!