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$.
输入数据
输出数据
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
样例输出
$ Mathjax font initiator $