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$ 個残る確率を求めてください。

入力

入力の最初の行には 3 つの整数 $N, r, h$ が与えられます。($1 \le N \le 5\,000, 0 \le r, h \le 1\,000\,000, 1 \le r + h$)

次の行には、R と H の 2 種類の文字からなる長さ $N$ の文字列が与えられます。これは物体の初期配置を左から右の順に表します。R は花の物体を、H は手の物体を表します。

最後の行には 2 つの整数 $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.