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

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

So, basically this problem can be considered as a simpler version of https://mirror.codeforces.com/blog/entry/74836 . I was wondering what can be the approach if we fix the size of the subset.

Given an array of size N , find the maximum bitwise or of elements in a subset of size K.

What can be the best(time complexity wise) possible approach for this problem apart from this ? Can anyone please help?

UPD: I had initially written Xor everywhere instead of Or. Sorry.

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

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

Clarification- Is the subset size fixed = k?

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

If K is a part of the input to the problem, then this is not a simpler version of the task "given an array of size N, find the maximum bitwise xor of any subset of elements", as you could:

  1. Take any input to the problem without any fixed $$$K$$$; say, it contains $$$N$$$ integers.
  2. Pad the array with $$$N$$$ zeroes (so that the new array has $$$N' = 2N$$$ integers).
  3. Set $$$K' = N$$$ (that is, $$$K' = \frac12 N'$$$).
  4. We get an instance of your problem, with an array of $$$N'$$$ integers, where we want to maximize the xor of elements in a subset of size $$$K'$$$.

Now, you can easily see that there exists a solution with XOR = $$$x$$$ to the new problem (array of size $$$N'$$$, we want to find a subset of size $$$K'$$$) if and only if there exists a solution with XOR = $$$x$$$ to the original problem. So, in some sense, your problem is at least as hard as the original problem.