#P4007. [清华集训 2017] 小 Y 和恐怖的奴隶主

    ID: 2938 远端评测题 2000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2017O2优化矩阵加速,矩阵优化概率论,统计期望清华集训

[清华集训 2017] 小 Y 和恐怖的奴隶主

Description

Xiao Y is an OIer who likes playing games. One day, she is playing a game and needs to fight a Boss.

Although this Boss has 1010010^{100} HP, it only brings one minion — a "Terrifying Slave Owner" with exactly mm HP.

This "Terrifying Slave Owner" has a special skill: whenever it takes damage but does not die (death means HP 0 \leq 0), and the number of the Boss's minions is less than the cap kk, it summons a new "Terrifying Slave Owner" with mm HP.

Now Xiao Y can make nn attacks. Each time she attacks, she chooses uniformly at random one target from the set consisting of the Boss and all of the Boss's minions, and reduces that target's HP by 11. She wants to know the expected total HP deducted from the Boss after nn attacks. To avoid precision issues, your answer should be taken modulo 998244353998244353.

Input Format

The first line contains three positive integers T,m,kT, m, k, where TT is the number of queries, and m,km, k are as defined in the statement.

Then follow TT lines. Each line contains a positive integer nn, representing a query asking for the expected HP deducted from the Boss after nn attacks.

Output Format

Output TT lines. For each query, output a non-negative integer — the answer modulo 998244353998244353.

It can be proven that the desired expectation is a rational number. Suppose it equals p/qp / q (gcd(p,q)=1)(\mathrm{gcd}(p,q) = 1). Then the number xx you output should satisfy pqx(mod998244353)p \equiv qx \pmod{998244353}.

3 2 6
1
2
3
499122177
415935148
471393168

Hint

[Sample 1 Explanation]

For the first query, the first attack has probability 12\frac{1}{2} to hit the Boss and probability 12\frac{1}{2} to hit the minion, so the answer is 12\frac{1}{2}. 12×499122177(mod998244353)1 \equiv 2 \times 499122177 \pmod{998244353}.

For the second query: if the first attack hits the Boss, then there is probability 12\frac{1}{2} that the second attack still hits the Boss and probability 12\frac{1}{2} that it hits the minion; if the first attack hits the minion, then a new minion (the "Terrifying Slave Owner") is summoned, so there is probability 13\frac{1}{3} that the second attack hits the Boss and probability 23\frac{2}{3} that it hits a minion. Therefore the answer is $\frac{1}{2}\times\frac{1}{2}\times2+\frac{1}{2}\times\frac{1}{2}\times1+\frac{1}{2}\times\frac{1}{3}\times1+\frac{1}{2}\times\frac{2}{3}\times0 = \frac{11}{12}$. 1112×415935148(mod998244353)11 \equiv 12 \times 415935148\pmod{998244353}.

[Tips]

The order of problems may not correspond to difficulty.

[Subtasks]

Across all test points, $1 \leq T \leq 1000, 1 \leq n \leq {10}^{18}, 1 \leq m \leq 3, 1 \leq k \leq 8$.

The scores and Constraints for each test point are as follows:

12058

Translated by ChatGPT 5