母牛的故事

题目:https://www.nowcoder.com/pat/2/problem/255

 1 #include <iostream>
 2 #include <algorithm>
 3 using namespace std;
 4 
 5 const int maxn = 60;
 6 long long f[maxn];
 7 void db(){
 8     f[1] = 1;
 9     f[2] = 2;
10     f[3] = 3;
11     f[4] = 4;
12     f[5] = 6;
13     for (int i = 6; i < maxn; i++){
14         f[i] = f[i - 1] + f[i - 3];
15     }
16 }
17 
18 int main(){
19     std::ios::sync_with_stdio(false);
20     int n;
21     db();
22     while (cin >> n){
23         cout << f[n] << endl;
24     }
25     //system("pause");
26     return  0;
27 }

 

posted @ 2018-01-09 21:17  ouyang_wsgwz  阅读(140)  评论(0编辑  收藏  举报