#P4260. [Code+#3] 博弈论与概率统计
[Code+#3] 博弈论与概率统计
Description
Alice and Bob are playing a two-player game. In each round, Alice wins with probability and loses with probability , and no tie occurs.
Both players start with points. When a player wins, they gain point; when a player loses, they lose point. Unfortunately, people in the world of game theory cannot comprehend negative numbers. Therefore, if someone loses a round while they have points, they will not be deducted any points (the opponent still gains point as usual). The game consists of rounds in total. Alice asks you to compute the expected value of her score at the end of the game.
“This is nothing. I, little L, can do it in a minute!” You, being even more skilled than little L, also get the answer easily. But just as you are about to tell Alice the answer, the god of the game theory world—temporaryDO—appears and brings an important piece of information: among these rounds, Alice wins exactly rounds!
Being familiar with conditional probability, you immediately realize that you need to adjust your computation to obtain the correct answer.
To avoid precision issues, please output the result modulo . That is, our testdata guarantees that the answer is a rational number with . You only need to find an integer such that .
Input Format
The first line contains two positive integers , , where is the number of test cases, and equals , i.e., Alice’s probability of winning each round.
Then follow lines. Each line contains two nonnegative integers , representing one test case.
Output Format
Output lines, each containing one integer, which is the answer for the corresponding test case.
3 500
1 1
2 3
4 4
500000004
200000002
728571435
Hint
In each round, Alice has probability to win.
- For the first test case, Alice’s win may occur in the first or second round, with equal probability. If she wins in the first round, her final score is ; otherwise, her score is . Hence the expectation is . Verification: .
- For the second test case, the expected value is .
- For the third test case, the expected value is .
Constraints and Conventions
- For 10% of the testdata, .
- For an additional 20% of the testdata, .
- For an additional 20% of the testdata, , , .
- For an additional 20% of the testdata, .
- For 100% of the testdata, , .
Credit: https://www.luogu.org/discuss/show?postid=35727
Translated by ChatGPT 5
京公网安备 11011102002149号