admin管理员组

文章数量:1123567

It is a famous question which asked about finding longest nondecreasing subsequence from a given array. The question is well studied and have O(n log n) time complexity solutions.

I have encountered a slightly different question: Given an array with at least 2 elements. Find TWO nondecreasing subsequences from it. These two subsequences should not share same array elements (same by index, not same by value). And I want to maximum and output the sum of lengths.

A simple DP solution could be done in O(n^4). And maybe some optimize may be done to make it works better while I don't know. So the first question is about:

  • What algorithm could we have to solve this question with best time complexity.

Another trivial idea is find the longest nondecreasing subsequence and remove it from original array, then repeat the finding again. This could be done in O(n log n). But I have no idea about:

  • Is greedy solution correct? If so, how to prove or argue it. If not, how to find out counterexample.
  • If not, can it serve as a valid approximation algorithm with some performance guarantees?

本文标签: algorithmMaximum the sum of lengths of two nondecreasing subsequence of given arrayStack Overflow