传送门;牛客
既然是了断局了,大家就随便玩玩数字呗。
已知一个数列前10项分别是
{0, 1, 1, 2, 4, 7, 13, 24, 44, 81}
小G不满足呀:我要更多的数!!!不给就不让你们玩了。
小G会问你第n项是什么数字,请回答这个顽皮的孩子吧。
emmm,是一道找规律的题目,刚开始我并没有发现规律,可能是我思维不太发散??,手模了很久之后才发现只是一个类斐波那契数列而已,当时一直观察前两项的关系,居然没想到前三项直接的关系…
规律
f[n]=f[n-1]+f[n-2]+f[n-3]
然后注意longlong的问题即可轻松秒杀啦!
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string.h>
#include <stack>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
#define root 1,n,1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
inline ll read() {
ll x=0,w=1;char ch=getchar();
for(;ch>'9'||ch<'0';ch=getchar()) if(ch=='-') w=-1;
for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
return x*w;
}
#define maxn 1000000
ll f[100];
int main() {
f[1]=0;f[2]=1;f[3]=1;
for(int i=4;i<=50;i++) {
f[i]=f[i-1]+f[i-2]+f[i-3];
}
int n;
while(scanf("%d",&n)!=EOF) {
cout<<f[n]<<endl;
}
return 0;
}