#P5299. [PKUWC2018] Slay the Spire
[PKUWC2018] Slay the Spire
Description
Jiutiao Kelian is playing a very interesting strategy game: Slay the Spire. At the beginning, her deck contains cards. Each card has a number written on it. There are two types of cards, with cards of each type:
-
Attack cards: After playing one, it deals damage equal to the number on the card.
-
Buff cards: After playing one, suppose the number on this buff card is . Then the numbers on all remaining attack cards will be multiplied by . It is guaranteed that the numbers on buff cards are all greater than 1.
Now Jiutiao Kelian will randomly draw cards from the deck with equal probability. Due to energy limits, she can play at most cards. Assume she always uses the strategy that can deal the maximum damage. Find the expected damage she can deal.
Suppose the answer is . You only need to output
$$\left (\text{ans}\times \frac{(2n)!}{m!(2n-m)!}\right) ~\bmod 998244353$$Here, means . In particular, .
Input Format
The first line contains a positive integer , denoting the number of test cases.
For each test case:
The first line contains three positive integers .
The second line contains positive integers , representing the values on each buff card.
The third line contains positive integers , representing the values on each attack card.
Output Format
Output lines. Each line contains a non-negative integer, representing the answer for each test case.
2
2 3 2
2 3
1 2
10 16 14
2 3 4 5 6 7 8 9 10 11
1 2 3 4 5 6 7 8 9 10
19
253973805
Hint
Sample Explanation
For example, Jiutiao Kelian draws attack cards and a buff card . The optimal strategy is to play the buff card first. Then the values of the attack cards become , and then she plays .
Constraints
For all testdata, , and .
It is guaranteed that the numbers on buff cards are all greater than 1.
Let denote the sum of over all test cases in the input.
For of the testdata, .
For of the testdata, .
For of the testdata, .
For another of the testdata, all attack cards have the same value.
For another of the testdata, .
For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号