#include<stdlib.h>
int a[8] = {1,2,1,3,5,6,7,8};
int findMaxAsc(int* a, int len, int index){
if(index == len || a[index] >= a[index + 1]){
return 1;
}
return 1+findMaxAsc(a,len,index+1);
}
int findMaxSubAsc(int* a, int len, int index){
int i = 0,j = 0,temp = 0;
int max = 0;
for(; i < len; i++){
temp = findMaxAsc(a, len, i);
if(max <= temp){
max = temp;
j = i;
}
}
int k = max;
for(; k > 0; k--){
printf("%d ",a[j++]);
}
return max;
}
int main(){
int result = findMaxSubAsc(a,8,0);
printf("result: %d ",result);
getchar();
}
寻找最长递增子序列
最新推荐文章于 2024-07-20 22:18:37 发布