码迷,mamicode.com
首页 > 其他好文 > 详细

最长非降序子序列

时间:2018-11-24 21:00:59      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:子序列   class   return   color   style   span   ret   max   turn   

输入:{5,3,4,8,6,7}

输出:4即{3,4,6,7}

 1 int MaxLength(int *a,int n)
 2 {
 3 int *b = new int ;
 4 int i,j;
 5 for(i=0;i<n;i++)
 6 {
 7 b[i] = 1;
 8 for(j=0;j<i;j++)
 9 {
10 if(a[i] > a[j] && b[j] + 1 > b[i])
11 b[i] = b[j] +1;
12 }
13 }
14 j=0;
15 int max = b[j];
16 for(j=1;j<n;j++)
17 {
18 if(b[j] > max)
19 max = b[j];
20 }
21 return max;
22 }

 

最长非降序子序列

标签:子序列   class   return   color   style   span   ret   max   turn   

原文地址:https://www.cnblogs.com/susidian/p/10013176.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!