1312:【例3.4】昆虫繁殖

传送门:http://ybt.ssoier.cn:8088/problem_show.php?pid=1312

 

 

【题目描述】

科学家在热带森林中发现了一种特殊的昆虫,这种昆虫的繁殖能力很强。每对成虫过x个月产y对卵,每对卵要过两个月长成成虫。假设每个成虫不死,第一个月只有一对成虫,且卵长成成虫后的第一个月不产卵(过X个月产卵),问过Z个月以后,共有成虫多少对?0≤X≤20,1≤Y≤20,X≤Z≤50。

【输入】

x,y,z的数值。

【输出】

过Z个月以后,共有成虫对数。

【输入样例】

1 2 8

【输出样例】

37

#include<iostream>
using namespace std;
#define N 60
long long int a[N],b[N],x,y,z;
int main()
{
    cin>>x>>y>>z;
    for(int i=1;i<=x;i++)
    {
        a[i]=1;//成虫个数均为1
        b[i]=0;//产卵数为零
    }
    for(int i=x+1;i<=z+1;i++)
    {
        b[i]=a[i-x]*y;
        a[i]=a[i-1]+b[i-2];
    }
    cout<<a[z+1]<<endl;
}

猜你喜欢

转载自www.cnblogs.com/jzxnl/p/11105522.html
3.4