此博客链接:https://www.cnblogs.com/ping2yingshi/p/12259683.html
母牛的故事(47min)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2018
#include<stdio.h> #include<math.h> #include<stdlib.h> int main(void) { int n; while(~scanf("%d",&n)) { if(n==0) break; int i; int sum=1; int oldcow=1;//能生母牛的母牛 int onecow=0;//生一年的母牛 int twocow=0;//生两年的母牛 int threecow=0;//生三年的母牛 for(i=1;i<n;i++) { oldcow=oldcow+threecow;这次能生的母牛等于上一次能生母牛的只数加上上一次 生三年的母牛 threecow=twocow; twocow=onecow; onecow=oldcow;//第一年生的母牛等于上一次能生母牛的只数 sum=oldcow+twocow+threecow+onecow; } printf("%d",sum); printf("\n"); } return 0; }
原文:https://www.cnblogs.com/ping2yingshi/p/12259683.html