問題一覧 > 通常問題

No.1336 Union on Blackboard

レベル : / AI推定難易度 : 600 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 217
作問者 : 蜜蜂 / テスター : Mitarushi
お気に入りにしたユーザー ProblemId : 5647 / 自分の提出
問題文最終更新日: 2021-03-24 23:49:40
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 278 (順位表) の他の問題:

Problem Statement

$N$ integers $A_1,A_2, \cdots\ ,A_N$ are written on a blackboard.

You perform the following operation $N-1$ times, reducing the numbers written on the blackboard to $1$ number.
・Choose $2$ of the numbers written on the blackboard uniformly at random. These $2$ numbers must be written in different places. Then, newly write on the blackboard the number obtained by adding together the sum and the product of the chosen $2$ numbers, and erase the chosen $2$ numbers from the blackboard.

Find the expected value of the $1$ number remaining at the end, after the $N-1$ operations.

Here, it is guaranteed that the expected value is a rational number greater than or equal to $0$.
If the expected value is $0$, output $0$.
Otherwise, it can be proved under the constraints of this problem that the expected value can be represented as an irreducible fraction $\frac{P}{Q}$ using integers $P,Q$ greater than or equal to $1$, and that there uniquely exists an integer $X$ such that $X \times Q \equiv P(\rm{mod} 10^9+7)$ and $0 \leq X < 10^9+7$. Output such an $X$.

$T$ test cases are given. Answer all of the test cases.

Input

Line $1$ of the input is as follows.
$T$
Then, $T$ test cases follow. Each of them is given in the following format.
$N$
$A_1\ A_2\ \cdots\ A_N$

・$1 \leq T \leq 100$
・$2 \leq N \leq 100$
・$0 \leq A_i \leq 200 (1 \leq i \leq N)$
・All inputs are integers

Output

Output $T$ lines. On the $i$-th line, output the expected value for the $i$-th test case modulo $\rm{mod} 10^9+7$, followed by a newline.

Sample

Sample 1
Input
2
3
1 1 0
2
1 1
Output
3
3

For test case number $1$, the number remaining at the end is each of the following with probability $\frac{1}{3}$.

・If $A_1,A_2$ are chosen first: after operation number $1$, $3,0$ remain on the blackboard, and after operation number $2$, $(3+0)+(3 \times 0)=3$ remains.
・If $A_1,A_3$ are chosen first: after operation number $1$, $1,1$ remain on the blackboard, and after operation number $2$, $(1+1)+(1 \times 1)=3$ remains.
・If $A_2,A_3$ are chosen first: after operation number $1$, $1,1$ remain on the blackboard, and after operation number $2$, $(1+1)+(1 \times 1)=3$ remains.

Therefore, for test case number $1$, the expected value of the $1$ number remaining at the end is $\frac{3+3+3}{3} \equiv 3(\rm{mod} 10^9+7)$.

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。