测评会员优惠活动进行中 · 开通 VIP,有效期内测评不限次 VIP 优惠中 · 测评不限次 立即查看

A11548. New Year and Arbitrary Arrangement

编程题 普及/提高-

题目描述

You are given three integers $k$ , $p_{a}$ and $p_{b}$ .

You will construct a sequence with the following algorithm: Initially, start with the empty sequence. Each second, you do the following. With probability $p_{a}/(p_{a}+p_{b})$ , add 'a' to the end of the sequence. Otherwise (with probability $p_{b}/(p_{a}+p_{b})$ ), add 'b' to the end of the sequence.

You stop once there are at least $k$ subsequences that form 'ab'. Determine the expected number of times 'ab' is a subsequence in the resulting sequence. It can be shown that this can be represented by $P/Q$ , where $P$ and $Q$ are coprime integers, and ![](/uploads/luogu/CF908D/250bff4a0d2d6149565f6e795de0dbd59e6a92a3_0f6a247bb268.png). Print the value of ![](/uploads/acgo/image/15be87d23f677cc5_aa9c9997c4a0.jpeg).

输入格式

The first line will contain three integers integer $k,p_{a},p_{b}$ ( $1<=k<=1000$ , $1<=p_{a},p_{b}<=1000000$ ).

输出格式

Print a single integer, the answer to the problem.

输入输出样例

输入 #1
1 1 1
输出 #1
2
输入 #2
3 1 4
输出 #2
370000006

说明/提示

The first sample, we will keep appending to our sequence until we get the subsequence 'ab' at least once. For instance, we get the sequence 'ab' with probability 1/4, 'bbab' with probability 1/16, and 'aab' with probability 1/8. Note, it's impossible for us to end with a sequence like 'aabab', since we would have stopped our algorithm once we had the prefix 'aab'.

The expected amount of times that 'ab' will occur across all valid sequences is 2.

For the second sample, the answer is equal to ![](/uploads/acgo/image/f4eb9888ecca96f2_9d33ac2a5482.jpeg).
上一题 去做题 下一题