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.