#P16822. [蓝桥杯 2026 国 Python B] 零段积分
[蓝桥杯 2026 国 Python B] 零段积分
Problem Description
Xiao Lan is doing a random string experiment. She has a sequence of length , and initially all positions are . After the experiment starts, each position in the sequence independently turns into with probability , and all other positions remain .
After the experiment ends, all consecutive 's are separated by 's into several segments.
Let the lengths of the non-empty consecutive zero segments from left to right be .
Xiao Lan defines the value of the sequence as
That is, the value is the sum of the products of the lengths of all adjacent zero segments. If the number of zero segments is less than , then the value is .
Now, please compute the expected value of , and output the result modulo .
Input Format
Input one line containing three integers , representing the length of the sequence, and the numerator and denominator of the probability that each position turns into .
It is guaranteed that , , and .
Output Format
Output one line with one integer, representing the expected value of modulo .
If the expected value is a fraction , output , where denotes the multiplicative inverse of modulo .
4 1 2
937500007
Hint
Sample Explanation
When and each position turns into with probability , all states occur with equal probability, but only the following states have a non-zero value:
| State | Zero-segment lengths | Value |
|---|---|---|
Therefore, . Modulo , equals .
Constraints and Conventions for Test Cases
For of the test cases, .
For all test cases, , , and .
Translated by ChatGPT 5