No.1336 Union on Blackboard
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.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
蜜蜂