I have the following algorithm which works well
I tried explaining it here for myself http://nemo.la/?p=943 and it is explained here http://www.geeksforgeeks.org/lon
To find the longest non-strictly increasing subsequence, change these conditions:
- If
A[i]
is smallest among all end candidates of active lists, we will start new active list of length1
.- If
A[i]
is largest among all end candidates of active lists, we will clone the largest active list, and extend it byA[i]
.- If
A[i]
is in between, we will find a list with largest end element that is smaller thanA[i]
. Clone and extend this list byA[i]
. We will discard all other lists of same length as that of this modified list.
to:
- If
A[i]
is smaller than the smallest of all end candidates of active lists, we will start new active list of length1
.- If
A[i]
is largest among all end candidates of active lists, we will clone the largest active list, and extend it byA[i]
.- If
A[i]
is in between, we will find a list with largest end element that is smaller than or equal toA[i]
. Clone and extend this list byA[i]
. We will discard all other lists of same length as that of this modified list.
The fourth step for your example sequence should be:
10
is not less than 10
(the smallest element). We find the largest element that is smaller than or equal to 10
(that would be s[0]==10
). Clone and extend this list by 10
. Discard the existing list of length 2. The new s
becomes {10 10}
.