QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#18882. Dstorv

Statistics

在一條直線上,有以固定速度移動的手形物體和花形物體。所有手形物體都向左移動,所有花形物體都向右移動。物體的總數為 $N$。

由於速度固定,同類物體之間不會碰撞。然而,花形物體與手形物體可能發生碰撞。在這種情況下,其中一個物體消失,另一個物體繼續以原來的速度沿原來的方向移動。

哪個物體消失由機率決定。花形物體以 $\frac{r}{r+h}$ 的機率消失。手形物體以 $\frac{h}{r+h}$ 的機率消失。$r, h$ 是輸入給定的整數。

經過足夠長的時間後,所有手形物體都已移向左方,所有花形物體都已移向右方,因此不會再發生碰撞。你的任務是計算所有碰撞結束後,恰好剩下 $A$ 個花形物體和 $B$ 個手形物體的機率。

輸入格式

輸入的第一行包含三個整數 $N, r, h$。($1 \le N \le 5\,000, 0 \le r, h \le 1\,000\,000, 1 \le r + h$)

下一行包含一個長度為 $N$、由 R、H 兩種字元組成的字串。它表示物體由左至右的初始排列。字元 R 表示花形物體,字元 H 表示手形物體。

最後一行包含兩個整數 $A, B$。($0 \le A, B \le N, 1 \le A + B \le N$)

輸出格式

可以證明,答案可以表示為 $\frac{P}{Q}$,其中 $P, Q$ 是互質整數,且 $Q \neq 0$ $(\mod 10^9 + 7)$。

輸出 $P \times Q^{-1}$ 對 $10^9 + 7$ 取模的值。

範例

輸入格式 1

4 1 1
RHRH
1 1

輸出格式 1

250000002

說明

範例的答案為 $\frac{1}{4}$。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.