![]() |
||||||||||
|
||||||||||
Problem H. Eat Cards, Have FunTime Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 94 Accepted Submission(s): 45 Problem Description $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$. Input 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. Output 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. Sample Input
Sample Output
Source | ||||||||||
|