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

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

I wonder how to solve this question

you have array of size n where 1 <= n <= 100 and 1 <= t <= 10^7 where every element of the array is less than 10^3 the array size is n*t and for every index > n -----> array[i] = array[i-n] you only given n elements for example if n = 3 and t = 2 and the given array is {1,2,3} so you should calculate the LIS for {1,2,3,1,2,3}

what is the longest increasing subsequence? any idea !?

  • Проголосовать: нравится
  • +10
  • Проголосовать: не нравится

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +30 Проголосовать: не нравится

Since there are at most 10^3 elements in the LIS, you only need to repeat the array 10^3 times. So now the array has at most 100 * 10^3 = 10^5 elements, and you can solve for the LIS normally.

»
6 лет назад, скрыть # |
Rev. 3  
Проголосовать: нравится +1 Проголосовать: не нравится

Compress $$$A$$$, and let $$$M=min(N, A)$$$. Now you have $$$O(MNlogM)$$$.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Any idea if there is duplicates ?

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

solution for longest nondecreasing subsequence. (let's still call it LIS)

call copy of array good if there are at least $$$2$$$ unequal elements in LIS from this copy. then there are at most $$$n$$$ good copies. and if most frequent element of array occurs $$$x$$$ times in it, then from every bad (not good) copy, there will be at most $$$x$$$ elements in LIS, and we can always position bad arrays in such a way that there are exactly $$$x$$$ elements from it in LIS, so if answer for $$$n$$$ copies is $$$A$$$, then answer for $$$t$$$ copies (if $$$t \gt n$$$) will be $$$A + (t-n)\cdot x$$$.