题解 | #吃糖果#

吃糖果

https://www.nowcoder.com/practice/72015680c32b449899e81f1470836097

#include <iostream>
using namespace std;
const int maxn=21;
long long f[maxn]={0};
int main() {
    int n;
    for(int i=1;i<=maxn;i++){
        if(i==1) f[i]=1;
        else if(i==2) f[i]=2;
        else f[i]=f[i-1]+f[i-2];
    } 
    while(scanf("%d",&n)!=EOF){
        printf("%lld\n",f[n]);
    }
    return 0;
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
1
1
分享

创作者周榜

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