Problem:
There are a pair of rabbits, from the 3rd month after the birth of a pair of rabbits every month, the small rabbit to the third month after the birth of a pair of rabbits, if the rabbit is not dead, ask each month the total number of rabbits?
Program Analysis:
The law of the Rabbit for the series 1,1,2,3,5,8,13,21 ....
Code:
Package com. Edward.suanfa;public class TZ {public static void main (string[] args) {//TODO auto-generated method stubfor (int i=1;i< 13;i++) System.out.println ("+i+" the number of rabbits is: "+tuzi.gettz (i));}} Class Tuzi {static int gettz (int n) {if (n<0) return 0;if (n==1| | n==2) return 1;return Gettz (n-1) +gettz (n-2);}}
Results:
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/88/7B/wKiom1f5C5ewmXp9AAAWQwxDG_o068.png-wh_500x0-wm_3 -wmp_4-s_3297065388.png "title=" Tuzi.png "alt=" Wkiom1f5c5ewmxp9aaawqwxdg_o068.png-wh_50 "/>
Bunny problem, optimization algorithm