(每日一练28752)题目名称:最长递增的区间长度
给一个无序数组,求最长递增的区间长度。如:[5,2,3,8,1,9] 最长区间 2,3,8 长度为 3 (注意:测试用例仅做参考,我们会根据代码质量进行评分)
非常唬人的代码质量评分出现太多次了。。。
n = int(input())
arr = list(map(int,input().split()))
ans,mx = 1,1
for i in range(1,n):
if arr[i] > arr[i - 1]:mx,ans = mx + 1,max(ans,mx + 1)
else:mx = 1
print(ans)
n = parseInt(readline())
arr = readline().split(' ').map(x => parseInt(x))
ans = 1,mx = 1
arr.forEach(function(x,y){if (y > 0 && x > arr[y - 1]){mx ++;ans = ans > mx ? ans : mx}else{mx = 1}})
print(ans)
相关推荐
动态规划:最长单调递增子序列
动态规划:最长单调递增子序列 A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1, a2, ..., aN) be any sequence (ai1, ai2, ..., aiK), where 1 <= i1 < i2 < ... < iK <= N. For example, sequence (1, 7, 3, 5, 9, 4, 8) has ordered subsequences, e. g., (1, 7), (3, 4, 8) and many others. All longest ordered subsequences are of length 4, e. g., (1, 3, 5, 8). Your program, when given the numeric sequence, must find the length of its longest ordered subsequence.
最长递增子序列(原创C语言)
这是我这两天才完成的原创代码,就是比较经典的求一个随机序列的最长递增子序列问题。例如: n=5 随机序列为 5 1 4 2 3,正确输出为1 2 3,即长度为3的递增子序列。里面附带实验详细说明,感兴趣的可以下来参考。 算法参考比较著名的<>(第二版,作者Thomas H Cormen) 如果感觉好的可以联系我qq410812645,欢迎和各位高手交流
C语言实现最长递增子序列问题的解决方法
主要介绍了C语言实现最长递增子序列问题的解决方法,采用递归的方法解决该问题,是非常经典的一类算法,需要的朋友可以参考下
求最长非递增子序列长度
要求:给定一个数字序列,任意次序,找出其中的最长非递增子序列的长度,输出该长度值. 程序用动态规划的方法予以实现.
PTA丨最长连续递增子序列
PTA丨最长连续递增子序列。 一篇文章带你快速了解!


