【问题标题】:Longest Increasing Sub sequence最长递增子序列
【发布时间】:2013-07-03 04:59:45
【问题描述】:

这是Wikipedia上给出的最长递增子序列的伪代码

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)

我已了解代码的工作原理。我唯一不能理解的是这个陈述的必要性(如果 j == L 或 X[i]

【问题讨论】:

标签: algorithm lis


【解决方案1】:

当有重复时,if 条件将失败

考虑X={2, 2, 2}

ifj=0L=1 时条件失败

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-15
    • 1970-01-01
    • 2018-11-01
    • 2011-09-02
    • 2015-12-12
    相关资源
    最近更新 更多