An interesting way to solve 739E

Правка en1, от krismaz, 2017-01-26 23:33:21

Hi everyone!

I've just solved 739E - Гоша выходит на охоту in an easy but interesting way. However, it's quite different from what's described in the editorial, and I couldn't find any accepted codes that use this approach. That's why I'm curious if anyone solved this problem like me, and if this is a well-known trick :)

First, there's an easy O(n3) DP solution to the problem: for each (i, x, y) compute the best score using x PokeBalls and y UltraBalls on i first Pokemon.

How to improve it? Let's randomly shuffle all Pokemon. If we looked at the first i of them, then we'd expect to use around PokeBalls, and UltraBalls there (a and b are the total amount of balls of each type), because the places where we used them in the optimal solution are now randomly distributed... even though positions where we use PokeBalls are not independent from positions where we use UltraBalls.

Now, using some random walk properties we can (I hope!) say, that it's really unlikely that we'll deviate from those expected values by more than . So we can just do the brutal DP, but constrain ourselves to x and y from a specific range of size . After that the solution is O(n2) and get's accepted: 24153740

All opinions are welcome. Thanks :)

Теги round 381, dp, random_shuffle

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский krismaz 2017-01-26 23:33:21 1356 Initial revision (published)