当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

7242:Sum Plus Product

题目描述
<tt>triplea</tt> has a box with $n(n\geq 1)$ balls inside, where on each of the balls there is an integer written. When there are <strong> at least two</strong> balls inside the box, <tt>triplea</tt> will do the following operation repeatedly:
<ol>
<li> Take two balls from the box, uniformly and independently at random. </li>
<li> Supposes the numbers written on the two balls are $a$ and $b$, respectively, then <tt>triplea</tt> will put a new ball in the box on which a number $S+P$ is written, where $S=a+b$ is the sum of $a$ and $b$, and $P=ab$ is the product of $a$ and $b$. </li>
</ol>

The operation will end when there is only one ball in the box. <tt>triplea</tt> wonders, what is the expected value of the number written on the last ball? He gets the answer immediately, and leaves this as an exercise for the reader, namely, you.
输入解释
The first line of input consists of an integer $T(1\leq T\leq 20)$, denoting the number of test cases.

For each test case, the first line of input consists of an integer $n(1\leq n\leq 500)$, denoting the initial number of balls inside the box.

The next line contains $n$ integers $a_1,a_2,\dots,a_n(0\leq a_i\lt 998244353)$, denoting the number written on each ball in the box, initially.
输出解释
For each test case, output an integer in one line, denoting the expected value of the number written on the last ball. Under the input constraints of this problem, it can be shown that the answer can be written as $\frac{P}{Q}$, where $P$ and $Q$ are coprime integers and $Q\not\equiv 0\pmod {998244353}$. You need to output $P\cdot Q^{-1}\pmod{998244353}$ as an answer, where $Q^{-1}$ is the modular inverse of $Q$ with respect to $998244353$.
输入样例
2
2
2 2
10
1 2 4 8 16 32 64 128 256 512
输出样例
8
579063023

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-7242

最后修改于 2022-09-15T06:17:35+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
20000/10000MS(Java/Others) 524288/524288K(Java/Others)