The story of a cow
来源:互联网 发布:良辰好景知几何 91baby 编辑:程序博客网 时间:2024/05/16 14:46
有一头母牛,它每年年初生一头小母牛。每头小母牛从第四个年头开始,每年年初也生一头小母牛。请编程实现在第n年的时候,共有多少头母牛?
n=0表示输入数据的结束,不做处理。
每个输出占一行。
2450
246
找到规律就阔以了,详见下
#include <iostream>#include <cstring>using namespace std;int main(){int n;while(cin>>n&&n){int sum[n+1],b=1;memset(sum,0,sizeof(sum));for(int i=1;i<=n;i++){if(i<4){sum[i]=sum[i-1]+b;}else if(i>=4){sum[i]=sum[i-1]+sum[i-3];}}cout<<sum[n]<<endl;}}
0 0
- The story of a cow
- The story of a typical software project.
- A Story of HealthyAt100--The 12th MiniStory of AJ
- A Story of Walden--The 13th MiniStory of AJ
- The Story of today.
- THE STORY OF O
- a story of 卓玛
- a story of love
- a story of Caching
- The Story of Creating Enterprises
- the story of new oriental
- Outliers: The Story of Success
- The End-of-Line Story
- A Story of Superior man--The 14th MiniStory of AJ
- A Christmas Carol——5、The end of the story
- The Story of the Olympics 奥林匹克故事
- The Story of the GnuTLS Bug
- The Story of A Web Designer’s Life in 15 GIFs
- 关于mongo的一些知识点
- mysql数据库学习(keep update)
- setsockopt 设置socket
- 错误:无法解析的外部符号"public:virtual struct CRuntimeClass...."
- 《研磨设计模式》读书笔记
- The story of a cow
- 细粒度图像分析
- bzoj 2086: [Poi2010]Blocks 单调栈
- 图文——怎样给GitHub上传本地代码(比如VS项目中的代码等)
- eclipse添加Pydev插件的过程
- Hive连接Mysql---FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask.
- 在salesforce中按照record type分类编辑详情页配置技巧
- 线材基础知识02——AWG线规
- python爬虫练手之斗图啦