题解 | 牛牛学数列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;
}
不一定要用数组


查看10道真题和解析