#include<stdio.h>
#include<stdlib.h>
int Max_Nums(int array[],int len)
{
int* temp = (int*)malloc(sizeof(int)*len);
if (temp == NULL)
return -1;
for (int i=len-1;i>-1;i--)
{
temp[i] = 1;
for (int j = i+1; j <len; j++)
{// 在array数组中从(array[i+1~len]>array[i])条件中选取 temp[i]=Max(temp[i+1~len])
if (array[i]<array[j]&&(temp[j]+1)>=temp[i])
{
temp[i] = temp[j] + 1;
}
}
}
int result = temp[0];
free(temp);
return result;
}
int main()
{
int array[] = {2,1,2,3,4,5,6};
printf("%d\n",Max_Nums(array,sizeof(array)/sizeof(int)));
return 0;
}
最长子序列
最新推荐文章于 2024-08-14 11:22:43 发布