思路:
斐波那契的长度应该很小,所以枚举前两个直接判,暴力。
没有仔细想过还需要标记一下初始两位相同的,因为也没试过map标记,1e6对存在是否可行(现在可行啦,以后大胆用 ————T4
multiset.lower_bound()没有注意到细节 multiset.end() ————T95
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef long long LL;
const int Maxn = 1e5 + 10;
map<pair<int,int>,int>mp;
vector<int>a, b;
multiset<int>st;
int n, x;
bool jud(int pm,int pn){
if(mp.find(make_pair(pm, pn)) != mp.end()) return false;
mp[make_pair(pm, pn)] = 1;
return true;
}
int get(int m){
if((int)st.size() == 0) return 0;
multiset<int>::iterator pos;
pos = st.lower_bound(m);
if(pos == st.end()) return false;
if((*pos) == m){
b.push_back(m);
st.erase(pos);
return 1;
}
return 0;
}
int main()
{
scanf("%d", &n);
for(int i=1;i<=n;i++){
scanf("%d", &x);
a.push_back(x);
st.insert(x);
}
int pre1, pre2, pre3;
int ans = 2, num;
sort(a.begin(), a.end());
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i == j) continue;
if(!jud(a[i], a[j])) continue;
b.clear();
pre1 = a[i];
pre2 = a[j];
pre3 = a[i] + a[j];
get(pre1);
get(pre2);
num = 2;
while(get(pre3)){
num++;
pre1 = pre2;
pre2 = pre3;
pre3 = pre1 + pre2;
}
for(int k=0;k<(int)b.size();k++)
st.insert(b[k]);
ans = ans > num ? ans : num;
}
}
printf("%d\n", ans);
return 0;
}