1013 Problem M
来源:互联网 发布:计算机专业不想编程 编辑:程序博客网 时间:2024/06/11 16:02
题意:
有一头母牛,它每年年初生一头小母牛。每头小母牛从第四个年头开始,每年年初也生一头小母牛。请编程实现在第n年的时候,共有多少头母牛?
思路
年:1 2 3 4 5 6 7 8
牛:1 2 3 4 6 9 13 19
前四年没有疑问 每年加一头从第五年开始 在第四年的基础上 第二年的牛各下了一头牛 第六年 在第五年的基础上 第三年的牛各下了一头牛 依次类推
第N年的母牛的数量是在他前一年的基础上 加上第N-3年的牛数
DP[I]=DP[I-1]+DP[I-3];
话说这牛也不会死吗???
#include<iostream>using namespace std;int DP[55];int main(){ DP[0] = 0; DP[1] = 1; DP[2] = 2; DP[3] = 3; DP[4] = 4; for (int i = 5;i <55;i++) { DP[i] = DP[i - 1] + DP[i - 3]; } int a; while (cin>>a&&a) { cout << DP[a]<<endl; } return 0;}
0 0
- 1013 Problem M
- 1013 Problem M
- 1013 Problem M
- 1013 Problem M
- 贪心算法 problem M(1013)
- Problem M
- Problem M
- Problem M
- Problem M
- Problem M
- Problem M
- Problem M
- Problem-M
- Problem M
- problem M
- 课程练习三-1013-problem M
- Problem M. Heaviside Functionz
- 专题一 Problem M
- Rails ActiveRecord的default_scope的坑
- python(一)变量,常量,编码,数据类型
- Shell 简易教程
- POJ 2240 Arbitrage
- 安卓_侧滑
- 1013 Problem M
- sqlalchemy 使用不同文件中的数据模型
- python(二)列表,元组,循环
- 爬虫技术入门(一)
- ICS 家庭作业2.65
- 222. Count Complete Tree Nodes
- 【BZOJ4319】cerc2008 Suffix reconstruction【构造】【后缀数组】
- PostgreSQL
- HTTP Content-type 对照表___http://tools.jb51.net/table/http_content_type