UVA, 11000 Bee

Source: Internet
Author: User

Test instructions: There is a bee, every year the drone produces a females and drone, and then die, females produce a drone, and then die, there is not a dead females, ask the number of drones and the total number of bees after n years

Idea: recursion + test Instructions

The number of drones this year is m[x], last year was m[x-1],

The number of females this year is f[x], last year for F[x-1]

According to test instructions, you can get:

M[X]=F[X-1]+M[X-1];

F[x]=m[x-1]+1

PS: According to recursion can also get the number of females to meet the Fibonacci sequence, namely: F[x]=f[x-1]+f[x-2]

Code:

1#include <iostream>2#include <cstdio>3 using namespacestd;4 Long LongN;5 #defineMAXN 1006 Long LongF[MAXN],M[MAXN];7 8 BOOLdatecin ()9 {Ten     if(SCANF ("%lld", &n)! =EOF) One     { A         if(n==-1) -             return false; -         return true; the     } -     return false; - } -  + voiddatecal () - { +     inti; Af[0]=1, m[0]=0, f[1]=1, m[1]=1; at      for(i=2; i<maxn;i++) -     { -f[i]=f[i-1]+f[i-2]; -m[i]=m[i-1]+f[i-1]; -     } - } in  - voidshowres () to { +printf"%lld%lld\n", m[n],m[n]+f[n]); - } the intMain () * { $ datecal ();Panax Notoginseng      while(Datecin ()) -     { the showres (); +     } A     return 0; the}

UVA, 11000 Bee

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.