【分析】
因为数组下标一般是非负数
所有用map去重
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<map>
#include<cmath>
using namespace std;
#define maxn 1010
int a[maxn];
int temp[maxn];
map<int,int>mp;
int main()
{
int m;
scanf("%d",&m);
mp.clear();
for(int i=0;i<m;i++)
{
scanf("%d",&a[i]);
mp[a[i]]++;
}
int x,y;
int ans=2;
int cnt;
for(int i=0;i<m;i++)
{
for(int j=0;j<m;j++)
{
if(i==j)
continue;//如果是break的话就会直接跳出第二个循环
// break;
x=a[i];
y=a[j];
if(x==0&&y==0)
{
if(mp[0]>ans)
{
ans=mp[0];
}
//continue;
break;
}
cnt=0;
mp[x]--;
mp[y]--;
temp[cnt++]=x;
temp[cnt++]=y;
while(mp[x+y]>0)
{
int z=x+y;
temp[cnt++]=z;
// mp[x]--;
//mp[y]--;
mp[z]--;
x=y;
y=z;
}
for(int i=0;i<cnt;i++)
{
mp[temp[i]]++;
}
if(cnt>ans)
ans=cnt;
}
}
printf("%d\n",ans);
return 0;
}