Memory Search Special--nkoj3749 Fibonacci retracement notation

Source: Internet
Author: User
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));
	}
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.