F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Problem H. Eat Cards, Have Fun

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 93    Accepted Submission(s): 44


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
2 2 1 2 1 2 5 3 11 5 2 3 4 1
 

Sample Output
333333337 841859064
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-05-11 11:21:10, Gzip enabled