Fighting_小银考呀考不过四级

Time Limit: 1000MS  Memory Limit: 65536KB

Problem Description

四级考试已经过去好几个星期了,但是小银还是对自己的英语水平担心不已。
小银打算好好学习英语,争取下次四级考试和小学弟小学妹一起拿下它!
四级考试的时候,监考老师会按考号分配固定的座位,但唯一不变的是每两个人之间肯定至少会留下两个空座位,原因相信大家都懂得。
那么问题来了,我们现在只关注教室里的一排座位,假设每排有n个座位,小银想知道这一排至少坐一个人的前提下,一共有多少种坐法。

Input

 
多组输入。
第一行输入整数n,代表教室里这一排的座位数目。(1 <= n <= 45)

Output

输出种类数目。输入输出各占一行,保证数据合法。

Example Input

1
3
5

Example Output

1
3
8

Hint

解题思路:我没想到什么原理,不停的列数据,找的规律。

Author

Casithy
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1000;
long long a[maxn];
long long f(int n)
{
    if(a[n])
        return a[n];
    else
        a[n] = f(n-1) + f(n-3) + 1;
    return a[n];
}
int main()
{
    int n;
    a[1] = 1;
    a[2] = 2;
    a[3] = 3;
    a[4] = 5;
    while(~scanf("%d", &n))
    {
        if(a[n])
            cout<<a[n]<<endl;
        else
            cout<<f(n)<<endl;
    }
    return 0;
}