gpt4 book ai didi

algorithm - 找出最大递增序列的长度

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:34:50 24 4
gpt4 key购买 nike

在整数数组中查找最大单调递增序列的长度的快速算法是什么。

最佳答案

来自 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)

关于algorithm - 找出最大递增序列的长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2310043/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com