Codeforces Round 1081 (Div. 2)
F
Fish Fight
Codeforces
2900
原题
← E→
翻译中…

In a pond, $n$ fish are in a line. For each fish $i$, its size is $a_i$, and any fish that eats it grows by $b_i$.

翻译中…

Alice picks fish $x$, Bob picks fish $y$. They alternate turns, starting with Alice's fish. On each player's turn, let their fish have size $p$. The fish will eat an adjacent fish with size $q$ that satisfies $p \geq q$. If more than one such fish exists, it chooses uniformly at random among them. Eating increases its size by the eaten fish's $b_i$.

翻译中…

If, at the start of its turn, a fish cannot eat any adjacent fish, it is instead eaten by its neighbours (A fish at an endpoint has one neighbour; a fish in the interior has two). If Alice's fish is eaten (either by Bob's fish or by her neighboring fishes), she immediately loses. Similarly, if Bob's fish is eaten (either by Alice's fish or by his neighboring fishes), he immediately loses.

翻译中…

Given Alice's and Bob's chosen fishes, compute the probability that Alice wins, modulo $10^9+7$.

翻译中…

More formally, let $M=10^9+7$. The answer can be written as an irreducible fraction $\frac{p}{q}$ with $q \not\equiv 0 \pmod M$. Output $p \, q^{-1} \bmod M$, the unique integer $x$ with $0 \le x \lt M$ and $x q \equiv p \pmod M$.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 500$). The description of the test cases follows.

翻译中…

The first line of each testcase contains a single integer $n$ ($2 \le n \le 3000$) — the number of fish in pond.

翻译中…

The second line contains two integers $x$ and $y$ ($1 \le x,y \le n$; $x \neq y$).

翻译中…

The third line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).

翻译中…

The fourth line contains $n$ integers $b_1, b_2, \ldots, b_n$ ($0 \le b_i \le 10^9$).

翻译中…

It is guaranteed that the sum of $n$ does not exceed $3000$ over all test cases.

翻译中…

Output

翻译中…

For each test case output a single integer which is the probability that Alice will win modulo $10^9 + 7$.

翻译中…

Note

翻译中…

In the first test case, Alice's fish can't eat any of the adjacent fish, hence Alice always loses.

翻译中…

In the second test case, Alice's fish has only one adjacent fish, which is Bob's fish, Since Alice's fish size is greater than or equal to Bob's fish size, Alice always wins.

翻译中…

In the third test case, in the first turn, Alice's fish can eat both the adjacent fish.

翻译中…

Case $1$: It eats fish $3$ (Bob's fish). Alice wins.

翻译中…

Case $2$: It eats fish $1$. The new size of Alice's fish will be $a_2 + b_1 = 4 + 0 = 4$. This will lead to Bob's fish always eating Alice's fish in the second turn. Alice loses.

翻译中…

Both cases are equally likely, hence the probability of Alice winning is $0.5$

翻译中…

In the fourth test case, the probability of Alice winning is $0.75$

翻译中…

样例

Input #1
6
2
1 2
1 2
1 1
2
1 2
2 1
1 1
3
2 3
1 4 4
0 1 1
5
4 2
2 6 5 5 3
1 2 1 3 2
7
3 5
1 1 1 1 1 1 1
0 0 0 0 0 0 1
10
8 3
2 5 9 3 8 4 5 6 2 7
1 3 5 2 7 3 4 2 2 3
Output #1
0
1
500000004
750000006
375000003
687500005
InputCopy OutputCopy
题目信息
题号
2192F
时间限制
4 s
内存限制
512 MB
标签
动态规划
数学
概率论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。