菲波拉契数制
Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others)
我们定义如下数列为菲波拉契数列:
F(1)=1 F(1)=1
F(2)=2 F(2)=2
F(i)=F(i−1)+F(i−2)(i>=3) F(i)=F(i−1)+F(i−2)(i>=3)
给定任意一个数,我们可以把它表示成若干互不相同的菲波拉契数之和。比如 13 13有三种表示法
13=13 13=13
13=5+8 13=5+8
13=2+3+8 13=2+3+8
现在给你一个数 n n,请输出把它表示成若干互不相同的菲波拉契数之和有多少种表示法。
Input
第一样一个数 T T,表示数据组数,之后 T T行,每行一个数 n n。
T≤105 T≤105
1≤n≤105 1≤n≤105
Output
输出 T T行,每行一个数,即 n n有多少种表示法。
Sample input and output
Sample Input | Sample Output |
---|---|
6 1 2 3 4 5 13 | 1 1 2 1 2 3 |
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<list>
#include<vector>
using namespace std;
const int maxn=50;
long long F[maxn],dp[100010];
void init(){
F[0]=F[1]=1;
for(int i=2;i<maxn;++i){
F[i]=F[i-1]+F[i-2];
}
dp[0]=1;
for(long long i=1;i<maxn;++i){
for(long long j=100000;j>=F[i];--j){
dp[j]+=dp[j-F[i]];
}
}
}
int main()
{
init();
long long i,j,k,n,t;
scanf("%lld",&t);
while(t--){
scanf("%lld",&n);
printf("%lld\n",dp[n]);
}
return 0;
}