其他分享
首页 > 其他分享> > 牛客竞赛-方块与收纳盒

牛客竞赛-方块与收纳盒

作者:互联网

链接:https://ac.nowcoder.com/acm/problem/14975

来源:牛客网

思路:

11和21的小方块可以看成f(1) f(2)===>斐波拉契数列,长度为i*1的收纳盒的方案数,设初始值f(1)=1 f(2)=2,状态转移f(i)=f(i-1)+f(i-2)

#include <bits/stdc++.h>

using namespace std;
long long a[1000];
int main()
{
    int n=100;
    a[1]=1;
    a[2]=2;
    for(int i =3 ; i <= n ;i++){
       a[i]=a[i-1]+a[i-2];
    }
    cin >> n;
    while(n--){
        int b;
        cin >> b;
        cout << a[b]<<endl;
    }

    return 0;
}

标签:收纳盒,int,cin,long,牛客,小方块,方块
来源: https://blog.csdn.net/kuangzeng/article/details/117379262