Title: Classical question: There are a pair of rabbits, from the 3rd month after the birth of a pair of rabbits every month, small 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.
1. Procedure analysis: Rabbit's rule for series 1,1,2,3,5,8,13,21 .... (not sure if this is the subject of the offer)
When I see this problem, if you do not see the back of the "Rabbit Rule for series 1,1,2,3,5,8,13,21", I think so, the rabbit is a birth of two, and the total is not the right, is the number, do not know the topic to express the same as I began to think, or with " The law of rabbits is the same as the 1,1,2,3,5,8,13,21 "information provided by the series."
If according to the "Rabbit Law for the series 1,1,2,3,5,8,13,21" information provided to analyze:
F (1) =1
F (2) =1
F (3) =f (2) +f (1) *1=2//f (1) * 1: The rabbit for the first month can produce a pair of each pair.
F (4) =f (3) +f (2) *1//f (2) * 1: The rabbit for the second month can produce a pair of each pair.
......
By analogy, we can conclude that
F (n) =f (n-1) +f (n-2) *1//n>=3
Java code:
public class Practise1 {
static int MONTH = 6;//months
static int TYPE = 1; A couple of pairs of
private int getcount (int month, int type) {
int sum = 0;
if (month = = 1 | | month ==2) {
sum = 1;
} else{
sum = GetCount (month-1,1) + GetCount (month-2,1) *type;
}
if (month = = month) {
System.out.println ("month=" +month+ "sum=" +sum);
}
return sum;
}
public static void Main (string[] args) {
(New Practise1 ()). GetCount (MONTH, TYPE);
}