Hey everyone,
I was trying to solve this problem from Topcoder. Correct solutions to the problem had used dp but aren't there infinite states when PointsToWinBy > 1?
Thanks.
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 166 |
2 | maomao90 | 163 |
2 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
Hey everyone,
I was trying to solve this problem from Topcoder. Correct solutions to the problem had used dp but aren't there infinite states when PointsToWinBy > 1?
Thanks.
Название |
---|
Since the constraints are small I think probability of winner being declared after 106 games is very small. Hence.we can simulate if for 106 games and take it to be answer.
Does this seem correct??
Ah Okay, so it's an approximate solution. Can we also find the exact solution?
On further googling ,I found out editorial describes an approximation solution.
Editorial
The exact solution:
Brute-force the first 2n - k steps, counting the probability of exiting along the way. We do this because, after that, we will be guaranteed that the winner (by difference) will have enough points to count.
Now, imagine a path with 2k + 1 vertices, that represent the difference between the two players [ - k...k]. States - k and k are absorbing (you cannot get out of them), and there are transitions from a state to its neighbours of probability s and 1 - s respectively.
This is a classical problem, called Gambler's Ruin (unfair coin version), and it has a closed form solution: https://en.wikipedia.org/wiki/Gambler%27s_ruin
You can also solve a more general version of this problem, on Markov chains (they are actually called absorbing Markov chains).
Thanks.