AT_arc223_d.Xpectation of Cards in Hand with Laboratory

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are AA "draw" cards and BB normal cards. Among the (A+B)!(A+B)! permutations of these A+BA+B cards, one is chosen uniformly at random, and the cards are stacked top to bottom in that order to form a deck. Then, KK cards are drawn from the top of the deck and placed in your hand. As long as your hand contains at least one draw card, repeat the following operation:

  • Discard one draw card from your hand. The discarded card is removed from your hand and does not return to the deck.
  • Let cc be the number of cards remaining in the deck. Add min⁡(c,2)\min(c,2) cards from the top of the deck to your hand.

Find the expected number, modulo 998244353998244353, of cards in your final hand.

Solve TT test cases per input.

Definition of modulo 998244353998244353

Under the constraints of this problem, it can be proved that the answer is a rational number, and that when it is expressed as an irreducible fraction PQ\frac{P}{Q}, it satisfies Q≢0(mod998244353)Q {{}\not\equiv{}} 0 \pmod{998244353}. Thus, the integer RR satisfying R×Q≡P(mod998244353),0≤R<998244353R \times Q \equiv P \pmod{998244353}, 0 \leq R < 998244353 is uniquely determined. Output this RR.

有 AA 张“抽牌”和 BB 张普通牌。在这些 A+BA+B 张牌的 (A+B)!(A+B)! 种排列中,等概率随机选择一种,并按该顺序自上而下叠放形成一副牌组。然后,从牌组顶部抽取 KK 张牌放入手牌中。只要手牌中至少含有一张抽牌,就重复执行以下操作:

  • 从手牌中弃掉一张抽牌(该牌被移出手牌,不会回到牌组中);
  • 设此时牌组中剩余 cc 张牌,则从牌组顶部再抽取 min⁡(c,2)\min(c,2) 张牌加入手牌。

求最终手牌中牌的数量的期望值,结果对 998244353998244353 取模。

每组输入包含 TT 个测试用例,需全部求解。

模 998244353998244353 的定义:

在本题约束下,可以证明答案为一个有理数;且当其表示为既约分数 PQ\frac{P}{Q} 时,满足 Q≢0(mod998244353)Q {{}\not\equiv{}} 0 \pmod{998244353}。因此,满足 R×Q≡P(mod998244353)R \times Q \equiv P \pmod{998244353} 且 0≤R<9982443530 \leq R < 998244353 的整数 RR 是唯一确定的。请输出该 RR。

输入格式

The input is given from Standard Input in the following format:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

Each test case caset\mathrm{case}_t is given in the following format:

AA BB KK

输入从标准输入给出,格式如下:

TT
case1\mathrm{case}_1
case2\mathrm{case}_2
⋮\vdots
caseT\mathrm{case}_T

每个测试用例 caset\mathrm{case}_t 的格式如下:

AA BB KK

输出格式

Output the answers over a total of TT lines. The tt-th line should contain the answer for the tt-th test case.

在总共 TT 行上输出答案。第 tt 行应包含第 tt 个测试用例的答案。

输入输出样例

  • 输入#1

    4
    2 2 3
    1 2 1
    10 20 4
    20 10 4

    输出#1

    2
    332748119
    944679050
    774829082

说明/提示

Sample 1 Explanation:
For the first test case, the initial hand always contains at least 11 draw card, and the deck has 11 card remaining. After performing the operation once, the hand contains 11 draw card and 22 normal cards. After performing the operation once more, the hand contains 00 draw cards and 22 normal cards.
For the second test case, the final hand size is 22 if the first drawn card is a draw card, and 11 if it is a normal card. The expected value is 13×2+23×1=43\frac{1}{3} \times 2 + \frac{2}{3} \times 1 = \frac{4}{3}.

Constraints

  • 1≤T≤1051 \leq T \leq 10^5
  • 1≤A,B1 \leq A, B
  • 1≤K≤A+B≤1071 \leq K \leq A+B \leq 10^7
  • The sum of A+BA+B over all test cases is at most 10710^7.
  • All input values are integers.

样例 1 解释:
对于第一个测试用例,初始手牌中始终至少包含 11 张抽牌,且牌堆中剩余 11 张牌。执行一次操作后,手牌中包含 11 张抽牌和 22 张普通牌;再执行一次操作后,手牌中包含 00 张抽牌和 22 张普通牌。
对于第二个测试用例,若首次抽到的牌为抽牌,则最终手牌大小为 22;若首次抽到的牌为普通牌,则最终手牌大小为 11。期望值为 13×2+23×1=43\frac{1}{3} \times 2 + \frac{2}{3} \times 1 = \frac{4}{3}。

约束条件

  • 1≤T≤1051 \leq T \leq 10^5
  • 1≤A,B1 \leq A, B
  • 1≤K≤A+B≤1071 \leq K \leq A+B \leq 10^7
  • 所有测试用例的 A+BA+B 之和不超过 10710^7。
  • 所有输入值均为整数。

输入解题思路,AI测评打分。不知道怎么写?

首页