昆虫繁殖

来源:互联网 发布:mac地址定位 编辑:程序博客网 时间:2024/06/08 10:47
Problem Description
科学家在热带森林中发现了一种特殊的昆虫,这种昆虫的繁殖能力很强。每对成虫过x个月产y对卵,每对卵要过两个月长成成虫。假设每个成虫不死,第一个月只有一对成虫,且卵长成成虫后的第一个月不产卵(过x个月产卵),问过了z个月以后,共有成虫多少对?0<=x<=20,1<=y<=20,x<=z<=50。
Input
输入有多组数据,每组数据为x、y、z的数值。
Output
对于每组数据输出过了z个月后共有成虫对数。
Sample Input
1 2 8
Sample Output

37

#include<stdio.h>#include<string.h>__int64 chengcong[60],luan[60];int x,y,z;int main(){//freopen("b.txt","r",stdin);while(scanf("%d %d %d",&x,&y,&z)==3){int i;memset(chengcong,0,sizeof(chengcong));memset(luan,0,sizeof(luan));for(i=1;i<=x;i++)chengcong[i]=1;for(i=x+1;i<=z+1;i++){luan[i]=chengcong[i-x]*y;chengcong[i]=chengcong[i-1]+luan[i-2];}printf("%I64d\n",chengcong[z+1]);}return 0;}


0 0
原创粉丝点击