[Python] basic recursion Fibonacci number - born small rabbit little rabbit


Initially a pair of small rabbits
grow to become the third month of a small rabbit rabbit mature
mature rabbit can generate a pair of small rabbits per month

Q n-th month has a few rabbits?


112358132134 5589144 that the number of conveyance column ...... Fibonacci

Observed: Relationship between each adjacent three numbers: third number = the number of two and pre

Analysis:
  find the n = number of rabbits months the n-1 month rabbit logarithmic + n-2-month rabbits log
  4 = 3 months months months + 2 -> 2 1 +
  3 = month 2 months 1 month + -> 2
  2 = 1 month
  1 month 1 =

1  # find the n-th number of months of total rabbit 
2  DEF get_rabbit_count (n):
 . 3      IF n == 1 :
 . 4          return 1
 . 5      elif n == 2 :
 . 6          return 1
 . 7      the else :
 . 8          return get_rabbit_count (n-1) get_rabbit_count + (2-n- )
 . 9  
10  Print (get_rabbit_count (. 5))   # . 5 
. 11  Print (get_rabbit_count (10))   # 55    

  

Guess you like

Origin www.cnblogs.com/Tree0108/p/12110053.html