0
点赞
收藏
分享

微信扫一扫

母牛的故事 HDU2018

kolibreath 2022-07-13 阅读 103


母牛的故事 HDU2018

母牛的故事 HDU2018_ios

递推,这一年新生下的牛,应该是三年前的牛的头数。

#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
int x[60],tt; //tt存储第几年,x存储第几年应该有几头牛
void solve(){
for(int i = 5;i <= tt;++i)
x[i] = x[i - 1] + x[i - 3];
cout<<x[tt]<<"\n";
}
signed main(){
IOS;
x[1] = 1,x[2] = 2,x[3] = 3,x[4] = 4; //初始化
while(cin>>tt && tt != 0)
solve();
return 0;
}

有多组数据也可以线打表,然后查询


举报

相关推荐

0 条评论