ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 2110. Remove or Maximize

Should this problem be solved with DP?
Posted by ComebackSeason 10 Jun 2017 22:57
Could someone provide any hint?



Edited by author 10.06.2017 23:14
Re: Should this problem be solved with DP?
Posted by Jane Soboleva (SumNU) 11 Jun 2017 04:35
Here's a brainless but simple way i did it.

0. Mini-optimization: remove all repeated numbers, leaving only unique ones, and reduce k respectively. Let A be the array with those unique numbers.
1. Make a list of indices that point to numbers which have 1st bit 1, 2nd bit 1, ..., 32nd bit 1. Like for example: L[1..32][0..nmax], L[5][0] — amount of numbers which have 1 on 5th bit, A[L[5][1]], A[L[5][2]], ... — those numbers.
2. Main algo. Make current_result = 0. Going from higher bit to lower (i = 1..32), if list is not empty (L[i][0] > 0) and ith bit is 0 in current_result, then choose random index j, and do current_result = current_result or L[i][j]. Increase i and repeat either till you reach the last bit or reach the limit of numbers to be deleted. Then update the best reached result.
3. Spam step 2 for a certain time. I initially decided to consume entire 2s, but apparently even 200ms is enough to ac.

Clever way is DP, yeah, but requires thinking :)