C5-小面包

上机通过率102/150/206,为什么大家都不做我的小面包

题目描述

又要发小面包了。这次我们有许多3*6的小面包和6*6的方糕,以及一个6*N的长方形盒子,强迫症的某楠一定要把它们整齐的装到盒子里,并且要尽量装满。请问有多少总不同装法?

输入

多组数据输入。 每组一个3的倍数N(0<=N<=750)

输出

对于每组数据,输出一行,为最终计算对1000007取模得到的结果。

输入样例

3
6

输出样例

1
3

样例解释

输入为3时,只能放入一块小面包。

输入为6时,有三种情况:

(1)竖着放两块小面包

(2)横着放两块小面包

(3)放一块方糕

先放代码

#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <ctime>

using namespace std;

int a[300];
int main()
{
    a[0] = 1;
    a[1] = 1;
    for(int i = 2; i < 300; i++)
        a[i] = (a[i-1] + 2 * a[i-2]) % 1000007;
    int n;
        while(cin>>n)
        {
            if(n==0)
                cout<<"1"<<endl;
            else
                cout<<a[n/3]<<endl;
        }

    return 0;
}

思路

先统统除3

f(1)=1,f(2)=3

当n>3时,1*2横放,有f(n-2)种,1*2竖放,有f(n-1)种,2*2铺,有f(n-2)种,所以 f(n)=f(n-1)+2*f(n-2)

来一张丑不拉几的图

猜你喜欢

转载自www.cnblogs.com/kubab119/p/11938756.html
今日推荐