随便给一串数列,求最长等差数列

3方水过,回头附n^2logn算法 (dp[i][j][k]=dp[i][k]+1)


#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<cctype>
#include<iostream>
#include<functional>
#include<algorithm>
using namespace std;
#define MAXN (10000+10)
int n,a[MAXN];
int main()
{
while (scanf("%d",&n)!=EOF)
{
for (int i=1;i<=n;i++) scanf("%d",&a[i]);
sort(a+1,a+1+n);
int ans=2;
for (int i=1;i<=n;i++)
for (int j=i+1;j<=n;j++)
{
int dd=a[j]-a[i],now=j,tot=2;
for (int k=j+1;k<=n;k++)
{
if (a[k]-a[now]==dd)
{
tot++;
now=k;
}
}
ans=max(ans,tot);

}
cout<<ans<<endl;

}



return 0;
}