P3749 Fibonacci Wedge notation |
Time limit:-MS space limit: 65536 KB |
Evaluation instructions: time limit 1000ms |
|
Problem Description
Fibonacci Wedge sequence 0,1,1,2,3,5,8,13,21, ...
An integer k is given, denoted by the addition and subtraction of the Fibonacci sequence. For example
10=5+5
19=21-2
17=13+5-1
1070=987+89-5-1
For the given number k, calculate the minimum number of Fibonacci wedges that need to be used. Input Format
The first line, an integer p, indicates that there is a P number (1<=p<=10)
The next P line, a positive integer K per line, represents the number (1<=K<=10^18) output format that needs to be computed
P lines, one integer per line, indicating that the corresponding number requires a minimum number of Fibonacci numbers to be used. Sample Input
4
7
4
16
1070
Sample Output
2
2
2
4
Serious Note: binary search lowerbound only to Fibonacci retracement 104th, more than burst Longlong, will re
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
using namespace std;
Map<long Long,long long > F;
Map<long long,bool > mark;
Long long fib[150];
Long long N;
Long Long DP (long long x) {
if (mark[x]) return f[x];
Mark[x]=true;
int R=lower_bound (fib+1,fib+1+104,x)-fib;
if (fib[r]==x) return f[x]=1;
int l=r-1;
Return F[x]=min (DP (FIB[R]-X), DP (X-FIB[L)) +1;
}
int main () {
long long t,i;
cin>>t;
Fib[1]=1;
Fib[2]=1;
for (i=2;i<=110;i++) fib[i]=fib[i-1]+fib[i-2];
while (t--) {
//f.clear ();
Mark.clear ();
scanf ("%i64d", &n);
printf ("%i64d\n", DP (n));
}
}