CF908D.New Year and Arbitrary Arrangement

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 . Print the value of .

给你三个整数 kk、pap_a 和 pbp_b。

你将按如下算法构造一个序列:初始时,序列为空。每一秒,执行以下操作:以概率 papa+pb\frac{p_a}{p_a + p_b} 在序列末尾添加字符 'a';否则(即以概率 pbpa+pb\frac{p_b}{p_a + p_b})在序列末尾添加字符 'b'。

当序列中至少包含 kk 个子序列 'ab' 时,停止构造过程。求最终序列中子序列 'ab' 的期望出现次数。可以证明该期望值可表示为 PQ\frac{P}{Q},其中 PP 与 QQ 互质,且 Q≢0(mod109+7)Q \not\equiv 0 \pmod{10^9+7}。请输出 PQ mod (109+7)\frac{P}{Q} \bmod (10^9+7) 的值。

输入格式

The first line will contain three integers integer k, p__a, p__b (1 ≤ k ≤ 1 000, 1 ≤ p__a, p__b ≤ 1 000 000).

第一行包含三个整数 kk、pap_a、pbp_b(1≤k≤1 0001 \leq k \leq 1\,000,1≤pa,pb≤1 000 0001 \leq p_a, p_b \leq 1\,000\,000)。

输出格式

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 .

第一个样例中,我们将不断向序列末尾追加字符,直到子序列 'ab' 至少出现一次为止。例如,得到序列 'ab' 的概率为 1/41/4,得到 'bbab' 的概率为 1/161/16,得到 'aab' 的概率为 1/81/8。注意,序列 'aabab' 是不可能作为最终结果出现的,因为当我们的前缀变为 'aab' 时,算法就会停止(此时已包含子序列 'ab')。

所有合法序列中 'ab' 出现次数的期望值为 22。

第二个样例的答案等于 。

输入解题思路,AI测评打分。不知道怎么写?

首页