Practice Race 5. Insect Breeding _ recursion

Source: Internet
Author: User
Insect Breeding Time limit:3000/1000ms (java/other) Memory limit:65535/32768k (Java/other) total submission (s): Accepted SUBM Ission (s): Font:times New Roman | Verdana | Georgia Font Size:←→problem Description Scientists have found a special insect in the tropical forest, which has a strong ability to reproduce. Each pair of adult X-per-month Y-pair eggs, each pair of eggs will be two months to grow into adults. Assuming that each adult does not die, the first month only a pair of adults, and eggs into the adult after the first month does not spawn (over X months spawning), asked after the z months, the total number of adults. 0<=x<=20,1<=y<=20,x<=z<=50. Input has multiple sets of data, each set of values x, Y, and Z. Output for each group of data out of the z month after the total number of adults. Sample Input
1 2 8
Sample Output
37
Thinking Analysis: The topic is also a recursive problem, the key is to find the rules of the previous data.
 code: #include <iostream> #include <stdio.h> #include <string.h> using namespace std; int main () {& nbsp
  __int64 a[60],b[60];
    int x,y,z;
    int i;     while (scanf ("%d%d%d", &x,&y,&z)!=eof)     {        memset (a,0,
sizeof (a));
        memset (b,0,sizeof (b));          for (i=1;i<=x;i++) {a[i]=1,b[i]=0}     for (i=x+1;i<=z+1;i++)   & nbsp  {        B[i]=y*a[i-x];         a[i]=a[i-1]+b[i-2];    }    
printf ("%i64d\n", a[z+1]);
   }     return 0; }

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.