找到最大的递增序列的长度 [英] Find the length of the largest increasing sequence
本文介绍了找到最大的递增序列的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么是快速算法在整数数组最大的单调递增序列的长度。
What's a fast algorithm for finding the length of largest monotonically increasing sequence in an array of integers.
推荐答案
从维基百科:最长递增子(O( N 的日志的 N 的))
From Wikipedia: Longest increasing subsequence (O(n log n))
L = 0
for i = 1, 2, ... n:
binary search for the largest positive j ≤ L such that X[M[j]] < X[i] (or set j = 0 if no such value exists)
P[i] = M[j]
if j == L or X[i] < X[M[j+1]]:
M[j+1] = i
L = max(L, j+1)
这篇关于找到最大的递增序列的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文