更新时间:2023-01-10 10:08:06
让最长的凸序列称为LCS; N> 1的最小长度为2。下面的算法不言自明。
Lets call the longest convex sequence as LCS; The minimum possible length for N>1 is 2. The algo below is self explanatory.
int LCS[N];
LCS[0] = 1; LCS[1] =2 ;
for(i=2;i<N;i++)
{
LCS[i] = 2;
for(j=1;j<i;j++)
{
for(k=0;k<j;k++)
{
if(LCS[j]-1 == LCS[k] && A[j] < (A[k] + A[i])/2 )
LCS[i] = max( LCS[i], 1+LCS[j]);
}
}
}