蓝桥杯练习 母牛的故事 找规律打表

题目链接http://www.dotcpp.com/oj/problem1004.html?sid=748195&lang=1#editor

 

找规律 当1<=i<=4 ,a[i]=i

           当  i>=5  ,a[i]=a[i-2]+a[i-3]+a[i-4]

#include<iostream>
using namespace std;
int n;
int a[60];
int main()
{
    for (int i = 1; i <= 54; i++){
        if (i <= 4) a[i] = i;
        else a[i] = a[i - 2] + a[i - 3] + a[i - 4];
    }
    while (cin >> n,n){
        cout << a[n] << endl;
    }
    return 0;
}
View Code

 

posted @ 2019-03-08 17:33  looeyWei  阅读(258)  评论(0)    收藏  举报