Блог пользователя HitmanBBa

Автор HitmanBBa, история, 11 лет назад, По-английски

Greetings.

There is any O(N LOG K) algorithm for longest not strictly increasing subsequence?

Example for longest not strictly increasing subsequence:

n = 3
a[] = {1, 1, 1}

Normal O(N LOG K) algorithm will give answer = 1. (Because it's work strictly increasing)

I need modified algorithm to give answer = 3.

Thanks in advance.

Теги lis, dp
  • Проголосовать: нравится
  • +8
  • Проголосовать: не нравится

»
11 лет назад, скрыть # |
← Rev. 3  
Проголосовать: нравится +18 Проголосовать: не нравится
vector<int> input, lis;
int n;//sizeof input
for (int i = 0; i < n; i++){
    int pos = upper_bound(lis.begin(), lis.end(), input[i]) - lis.begin();
    if (pos == lis.size())
         lis.push_back(input[i]);
    else
         lis[pos] = input[i];
}
//lis.size() is the answer