Problem H. Problem H. Eat Cards, Have Fun

时间限制 3000 ms   内存限制 256 MB

$n$ cards with distinct integers $a_i$ are arranged in a circle, numbered from $1$ to $n$ in clockwise order.
Initially, Kazari holds an empty array $A$ and stands at card $1$.
She will keep performing the following two operations until all cards have been eaten.
* She appends the number on the current card to $A$ and eats the current card, with probability $\frac{p} {q}$.
* Move to the next card that has not been eaten in clockwise order.
It is obvious that $A$ is a $n$-permutation at the end. Define its value as $k$ if it is $k$-th lexicographically smallest among all $n$-permutations. Please help her work out the expected value of $A$.
 

输入数据

The first line of the input contains an integer $T$ denoting the number of test cases.
Each test case starts with a positive integer $n$ $(n \le 300, \sum{n} \le 1500)$, denoting the number of cards.
The second line contains two integers $p, q$ $(0 < p < q \le 10 ^ 9, \gcd(p, q) = 1)$, representing the probability.
The third line contains $n$ integers, the $i$-th integer represents the number $a_i$ $(1 \le a_i \le n)$ on the $i$-th card.
 

输出数据

For each test case, print the expected value $E$ modulo $10 ^ 9 + 7$.
Let $E$ be an irreducible fraction $\frac{a} {b}$, define $E \equiv a \hat{b} \pmod p$, where $b \hat{b} \equiv 1 \pmod p$, assuming $p$ is a prime.
 

样例输入

复制
2
2
1 2
1 2
5
3 11
5 2 3 4 1

样例输出

复制
333333337
841859064

提交

请先 登录

© 2025 FAQs Contact About