题解 | 牛牛学数列6

牛牛学数列6

https://www.nowcoder.com/practice/b6321648517247b2ac2e2f80cbc63ae1

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a=0,b=1,c=1,d;
    if(n==1){
        cout << 0;
    }
    else if(n>= 2 && n<=3){
        cout << 1;
    }
    else if(n >= 4){
        for (int m = 3;m<n;m++){
            d = a+2*b+c;
            a = b;
            b = c;
            c = d;
        }
        cout << d;
    }
    return 0;
}
不一定要用数组

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务