Recursion two: Ask the mouse to give birth to children.

Source: Internet
Author: User

There are a pair of mice, it produces a pair of mice every one months, small mice in 3 months after adulthood, will produce mice.After 3 years, how many mice will be in total, regardless of mouse death?  1th months after the situation:    adult mice: 1 to                     Newborn mice: 1 to   &N Bsp One-month-old rats: 0 pairs             Two-month-old mice: 0 pairs     1th months after the total of mice: 2 to 2nd months after the situation:    adult mice: 1 to &NB Sp                   New mouse: 1 to     One-month-old mouse: 1 to       &NBSP ;     Two-month-old mice: 0 pairs     2nd months after the total number of mice: 3 to 3rd months after the situation:    adult mice: 1 to             &N Bsp       Newborn mice: 1 pair     One-month-old mouse: 1 to             Two-month-old mouse: 1 to     3rd month After a total of mice: 4 to 4th months after the situation:    adult mice: 2 to                     Newborn Mouse: 2 to     One-month-old mice: 1 pairs             Two-month-old mice: 1 pair     4th month after total mice: 6 to 5th months after condition:    adult Rats : 3 to                     New mouse: 3 to     One-month-old mouse: 2 to     & nbsp &nbsP     Two-month-old mice: 1 pairs     5th months after the total number of mice: 9 to 6th months after the situation:    adult mice: 4 to             &N Bsp       Newborn mice: 4 pair     One-month-old mouse: 3 to             Two-month-old mouse: 2 to     6th month After a total of mice: 13 to 7th months after the situation:    adult mice: 6 to                     Newborn Mouse: 6 to     One-month-old mice: 4 pairs             Two-month-old mice: 3 pair     7th month after total mice: 19 to 8th months after condition:    adult Mouse: 9 to                     Newborn Mouse: 9 to     One-month-old mouse: 6 to             Two-month-old mice: 4 pairs     8th months after the total number of mice: 28 to 9th months after the situation:    adult mice: 13 to                   Newborn mice: 13 to     One-month-old mouse: 9 to             Two-month-old mouse: 6 pair     Total mice after the 9th month: 41 to 10th months after the situation:    adult mice: 19 to                   NEW Raw MICE: 19 pairs   &NBsp One-month-old mice: 13 pairs           Two-month-old mice: 9 pairs     10th months after the total of mice: 60 to 11th months after the situation:    adult mice: 28 to &nbs P                 New mouse: 28 to     One-month-old mouse: 19 to         &N Bsp Two-month-old mice: 13 pairs     11th months after the total number of mice: 88 to 12th months after the situation:    adult mice: 41 to               &NB Sp   Newborn mice: 41 pairs     One-month-old mice: 28 pairs           Two-month-old mice: 19 pairs     12th month after total mice: 129 to 13th Months after:    adult mice: 60 to                   Newborn mice: 60 to     One-month-old mouse : 41 pairs           Two-month-old mice: 28 pairs     13th month after total mice: 189 to 14th month after situation:    adult mice: 88 to   &NBS P               New mouse: 88 to     One-month-old mouse: 60 to           Two The Rat of the moon: 41 pairs     14th months after the total of mice: 277 to 15th months after the situation:    adult mice: 129 to               &NB Sp &nThe newborn mouse: 129 pairs     One-month-old mice: 88 pairs           Two-month-old mice: 60 pairs     15th month after the mice : 406 to 16th months after the situation:    adult mice: 189 to                   Newborn mice: 189 to   &NBSP ; One-month-old rats: 129 pairs           Two-month-old mice: 88 pairs     16th months after the total number of mice: 595 to 17th months after the situation:    adult mice: 277 pairs                   new mice: 277 to     One-month-old mouse: 189 to       & nbsp   Two-month-old mice: 129 pairs     17th months after the total number of mice: 872 to 18th months after the situation:    adult mice: 406 to                   Newborn mice: 406 pair     One-month-old mouse: 277 to           Two-month-old mouse: 189 to     18th After the month a total of mice: 1278 on the 19th month after the situation:    adult mice: 595 to                   Newborn mice: 595 to &nbs P   One-month-old mice: 406 pairs           Two-month-old mice: 277 pair     19th month after total mice: 1873 to 20th month after situation:    Adult mice: 872 pairs       &NBsp           new mice: 872 to     One-month-old mouse: 595 to           Two-month-old mouse: 406 to &NB Sp   20th months after a total of mice: 2745 to 21st months after the situation:    adult mice: 1278 to                 Newborn mice: 1278 For     One-month-old mice: 872 pairs           Two-month-old mice: 595 pair     21st month after the total mouse: 4023 to 22nd months after the situation:    Adult mice: 1873 to                 Newborn mice: 1873 to     one-month-old mouse: 1278 to   & nbsp     Two-month-old mice: 872 pairs     22nd months after the total number of mice: 5896 to 23rd months after the situation:    adult mice: 2745 to         &NBS P       Newborn mice: 2745 pair     One-month-old mouse: 1873 to         Two-month-old mouse: 1278 to     23rd month after There are mice: 8641 to 24th months after the situation:    adult mice: 4023 to                 Newborn mice: 4023 to   &NBSP ; One-month-old mice: 2745 pairs         Two-month-old mice: 1873 pairs     24th months after the total number of mice: 12664 to 25th months after the situation:    adult mice: 5896 pairs   &NBSp             New mouse: 5896 to     One-month-old mouse: 4023 to         Two-month-old mouse: 2745 For     Total mice after the 25th month: 18560 to 26th months after the situation:    adult mice: 8641 to                 NEW Raw mice: 8641 pairs     One-month-old mice: 5896 pairs         Two-month-old mice: 4023 pairs     26th months after the total number of mice: 27201 to 27th months after the situation:     Adult mice: 12664 to                         new mouse: 12664 pair & nbsp   One-month-old mice: 8641 pairs         Two-month-old mice: 5896 pair     27th month after total mice: 39865 to 28th months after the situation:    adult rats : 18560 to                         New mouse: 18560 to     one months old Mice: 12664 pairs                 Two-month-old mice: 8641 pairs     28th month after total mice: 58425 to 29th month after situation: & nbsp   Adult mice: 27201 to                         New mouse: 27201 to   & nbsp Mice with one months old: 18560 pairs of                 Two-month-old mice: 12664 pairs     29th month after total mice: 85626 to 30th months after the situation:    Adult mice: 39865 to                         New mouse: 39865 to   & nbsp One-month-old rats: 27201 pairs                 Two-month-old mice: 18560 pairs     30th month after the mice : 125491 to 31st months after the situation:    adult mice: 58425 to                       &N BSP, newborn mouse: 58425 pairs     One-month-old mice: 39865 pair                 Two-month-old mouse: 27201 pair     Total mice after the 31st month: 183916 to 32nd months after the situation:    adult mice: 85626 pair                         Newborn mice: 85626 to     One-month-old mouse: 58425 to               &NBS p; two-month-old mice: 39865 pairs     32nd months after the total number of mice: 269542 to 33rd months after the situation:    adult mice: 125491 to           & nbsp           freshmenMice: 125491 pairs     One-month-old mice: 85626 to                 Two-month-old mice: 58425 to   &NBS P After the 33rd month, a total of mice: 395033 to 34th months after the situation:    adult mice: 183916 to                       Newborn mice: 183916 pairs     One-month-old mice: 125491 to               Two-month-old mice: 85626 to     34th months after a total of mice: 578949 to 35th months after the situation:    adult mice: 269542 pairs                       Newborn mice: 269542 pairs     One-month-old mice: 183916 to               Two-month-old mice: 125491 For     Total mice after the 35th month: 848491 to 36th months after the situation:    adult mice: 395033 to               &NBSP ;       Newborn mice: 395033 pairs     One-month-old mouse: 269542 to               Two-month-old mouse: 183916 pairs     36th months after the total of mice: 1243524 pairs of analysis: This problem with the loop can be used for a long time, but also very good to do, but it will be easier to do with recursion, as long as you find the back of a number with the preceding number of links between the line, The hardest part of the problem is finding the rules,as long as the law found the writing code is just the right thing to do.

public class Test {private static int sum;public static void Main (string[] args) {System.out.println (Fibonacci (36));}private static int Fibonacci (int i) {if (i==0)sum = 2;if (i==1)sum = 2;if (i==2)sum = 3;if (i==3)sum = 4;if (i==4)sum = 6;if (i>=5)sum = Fibonacci (i-2) +fibonacci (i-3) +fibonacci (i-4);return sum;}}

Recursion two: Ask the mouse to give birth to children.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.