A11548 | New Year and Arbitrary Arrangement
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 .
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 .
输入格式
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 .
The expected amount of times that 'ab' will occur across all valid sequences is 2.
For the second sample, the answer is equal to .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted