#P15985. [PA 2026] 骰子 / Kostki

    ID: 18023 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>动态规划 DP2026PA(波兰)

[PA 2026] 骰子 / Kostki

Problem Description

There are nn players playing a dice game using a fair kk-sided die (the faces are numbered from 11 to kk, i.e. each roll results in any value from 11 to kk with probability 1k\frac{1}{k}). Initially, every player's score is zero.

In one move, the player with the smallest score rolls the die and adds the result to their score. If at some moment multiple players are tied for the smallest score, then one of them is chosen uniformly at random to take the move.

The game ends when any player's cumulative score reaches mm or more. Find the expected number of moves.

Input Format

The only line contains three integers nn, kk, mm (1n,k,m1061 \le n, k, m \le 10^6), representing the number of players, the number of faces on the die, and the score needed to win.

Output Format

Output one number: the expected number of moves, taken modulo M=109+7M = 10^9 + 7.

It can be proven that the answer can be written as a rational number p/qp/q, where pp and qq are integers and q0(modM)q \ne 0 \pmod{M}. Output the value of pq1modMp \cdot q^{-1} \bmod M. In other words, output the value xx such that 0x<M0 \le x < M and xqp(modM)x \cdot q \equiv p \pmod{M}.

2 4 3
457031255

Hint

Sample Explanation

There are two players, a four-sided die, and the target score is 33. On the first roll, if the player rolls 33 or 44, the game ends immediately (with probability 12\frac{1}{2}). Otherwise, the second player rolls. Similarly, if they roll 33 or 44, the game ends (also with probability 12\frac{1}{2}). If the game still does not end, then with probability 14\frac{1}{4} both players have 11 point (case A), with probability 12\frac{1}{2} one player has 11 point and the other has 22 points (case B), and with probability 14\frac{1}{4} both players have 22 points (case C).

  • Case A: The first player rolls, and with probability 34\frac{3}{4} the game ends after the third move. If it does not end, the second player rolls, and with probability 34\frac{3}{4} the game ends after the fourth move. If it still does not end, then the game must end after the fifth move (the player with 22 points rolls and gains at least 11 more point).

  • Case B: The first player rolls, and with probability 34\frac{3}{4} the game ends after the third move, and with probability 14\frac{1}{4} it ends after the fourth move.

  • Case C: The game must end after the third move.

Combining the cases above, the total expectation is:

$$\frac{1}{2} \cdot 1 + \frac{1}{4} \cdot 2 + \frac{1}{4} \cdot \left( \frac{1}{4} \cdot \left( \frac{3}{4} \cdot 3 + \frac{1}{4} \cdot \frac{3}{4} \cdot 4 + \frac{1}{4} \cdot \frac{1}{4} \cdot 5 \right) + \frac{1}{2} \cdot \left( \frac{3}{4} \cdot 3 + \frac{1}{4} \cdot 4 \right) + \frac{1}{4} \cdot 3 \right) = \frac{461}{4^4}$$

Since 2561=285156252modM256^{-1} = 285156252 \bmod M, and 461285156252457031255(modM)461 \cdot 285156252 \equiv 457031255 \pmod{M}, the answer is 457031255457031255.

Translated by ChatGPT 5