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.