# 斐波那契数列——UPC

1
16

4

#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define wuyt main
typedef long long ll;
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
///#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
///char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();
if(c == '-')Nig = -1,c = getchar();
while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();
return Nig*x;}
const ll inf = 1e15;
const ll INF = 0x3f3f3f3f;
const int maxn = 2e5 + 7;
const int mod = 1e9 + 7;
ll gcd(ll a,ll b)
{
ll t;
while(b!=0)
{
t=a%b;
a=b;
b=t;
}
return a;
}
ll qPow(ll x, ll k)
{
ll res = 1;
while(k) {
if(k&1)
res=(res*x);
k>>=1;
x=(x*x);
}
return res;
}
ll maxx=-1;
ll minn=inf;
ll num2[maxn];
ll num[maxn];
ll res,ans;
int sum=0;
map<string,ll> mp;
vector<ll> vet;
priority_queue <int ,vector<int> ,greater<int> > xiaogen;
queue <ll> duilie;
priority_queue <int ,vector<int> ,less<int> > que;
ll feib[maxn];
ll dp[maxn][3];
int main()
{
///1 2 3
/**
注意这里的数列顺序是 1 2 3 5 8
不是之前的 1 1 2 3 5 8
**/
feib[1]=1,feib[2]=2;
for(int i=3;i<=1e3;i++) feib[i]=feib[i-1]+feib[i-2];
while(cnt--){
memset(dp,0,sizeof dp);
memset(num,0,sizeof num);
int pos;/// 记录位置
for(int i=1;i<=1000;i++)
{
if(feib[i]>=n){
pos=i;
break;
}
}
int temp=0;
for(int i=pos;i>0;i--){
if(n>=feib[i])
{
///¼õÈ¥
n-=feib[i];
num[++temp]=i;
}
}
sort(num+1,num+1+temp);
dp[1][1]=1;
dp[1][0]=(num[1]-1)/2;
for(int i=2;i<=temp;i++){
dp[i][1]=dp[i-1][0]+dp[i-1][1];
dp[i][0]=dp[i-1][1]*((num[i]-num[i-1]-1)/2)+dp[i-1][0]*((num[i]-num[i-1])/2);
}
///test:
///cout<<pos<<endl;
///cout<<temp<<endl;
///cout<<<<endl;
printf("%lld\n",dp[temp][1]+dp[temp][0]);
}

return 0;
}

10-23 3726

10-16 130

02-18 178

06-14 556

05-31 67

03-25 443

03-29 95

#### 斐波那契数列——JAVA

©️2020 CSDN 皮肤主题: 深蓝海洋 设计师: CSDN官方博客

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。