Topic: Given a sequence of length n, the maximal linear sub-sequence is obtained
F[I][J] Indicates the current arithmetic progression last number is a[i], the penultimate number is the longest length of J
Then there are f[i][a[j]]=max{2,f[j][a[j]*2-a[i]]+1}
Note Output 1 when n=1
Time complexity O (N^2LOGN)
#include <map> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm > #define M 2020using namespace Std;int n,ans,a[m];map<int,int> F[m];//f[i][j] Indicates the current arithmetic progression last number is a[i], The penultimate number is the longest length of J int main () {int i,j;cin>>n;if (n==1) return cout<<1<<endl,0;for (i=1;i<=n;i++) scanf ("%d", &a[i]); for (i=1;i<=n;i++) for (j=1;j<i;j++) {F[i][a[j]]=max (f[i][a[j]],2); F[i][a[j]]=max (F[i][a[j] ],f[j][a[j]*2-a[i]]+1); Ans=max (Ans,f[i][a[j]);} Cout<<ans<<endl;return 0;}
Bzoj 3357 Usaco2004 arithmetic progression dynamic planning