A16140 | Expected Destruction
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You have a set $S$ of $n$ distinct integers between $1$ and $m$ .
Each second you do the following steps:
1. Pick an element $x$ in $S$ uniformly at random.
2. Remove $x$ from $S$ .
3. If $x+1 \leq m$ and $x+1$ is not in $S$ , add $x+1$ to $S$ .
What is the expected number of seconds until $S$ is empty?
Output the answer modulo $1\,000\,000\,007$ .
Formally, let $P = 1\,000\,000\,007$ . It can be shown that the answer can be expressed as an irreducible fraction $\frac{a}{b}$ , where $a$ and $b$ are integers and $b \not \equiv 0 \pmod{P}$ . Output the integer equal to $a \cdot b^{-1} \bmod P$ . In other words, output an integer $z$ such that $0 \le z < P$ and $z \cdot b \equiv a \pmod{P}$ .
Each second you do the following steps:
1. Pick an element $x$ in $S$ uniformly at random.
2. Remove $x$ from $S$ .
3. If $x+1 \leq m$ and $x+1$ is not in $S$ , add $x+1$ to $S$ .
What is the expected number of seconds until $S$ is empty?
Output the answer modulo $1\,000\,000\,007$ .
Formally, let $P = 1\,000\,000\,007$ . It can be shown that the answer can be expressed as an irreducible fraction $\frac{a}{b}$ , where $a$ and $b$ are integers and $b \not \equiv 0 \pmod{P}$ . Output the integer equal to $a \cdot b^{-1} \bmod P$ . In other words, output an integer $z$ such that $0 \le z < P$ and $z \cdot b \equiv a \pmod{P}$ .
输入格式
The first line contains two integers $n$ and $m$ ( $1 \leq n \leq m \leq 500$ ) — the number of elements in the set $S$ and the upper bound on the value of the elements in $S$ .
The second line contains $n$ integers $S_1,\,S_2,\,\dots,\,S_n$ ( $1 \leq S_1 < S_2 < \ldots < S_n \leq m$ ) — the elements of the set $S$ .
The second line contains $n$ integers $S_1,\,S_2,\,\dots,\,S_n$ ( $1 \leq S_1 < S_2 < \ldots < S_n \leq m$ ) — the elements of the set $S$ .
输出格式
Output a single integer — the expected number of seconds until $S$ is empty, modulo $1\,000\,000\,007$ .
输入输出样例
输入 #1
2 3 1 3
输出 #1
750000009
输入 #2
5 10 1 2 3 4 5
输出 #2
300277731
输入 #3
5 10 2 3 6 8 9
输出 #3
695648216
输入 #4
1 100 1
输出 #4
100
For test 1, here is a list of all the possible scenarios and their probabilities:
1. $[1, 3]$ (50% chance) $\to$ $[1]$ $\to$ $[2]$ $\to$ $[3]$ $\to$ $[]$
2. $[1, 3]$ (50% chance) $\to$ $[2, 3]$ (50% chance) $\to$ $[2]$ $\to$ $[3]$ $\to$ $[]$
3. $[1, 3]$ (50% chance) $\to$ $[2, 3]$ (50% chance) $\to$ $[3]$ $\to$ $[]$
Adding them up, we get $\frac{1}{2}\cdot 4 + \frac{1}{4} \cdot 4 + \frac{1}{4} \cdot 3 = \frac{15}{4}$ . We see that $750000009 \cdot 4 \equiv 15 \pmod{1\,000\,000\,007}$ .
1. $[1, 3]$ (50% chance) $\to$ $[1]$ $\to$ $[2]$ $\to$ $[3]$ $\to$ $[]$
2. $[1, 3]$ (50% chance) $\to$ $[2, 3]$ (50% chance) $\to$ $[2]$ $\to$ $[3]$ $\to$ $[]$
3. $[1, 3]$ (50% chance) $\to$ $[2, 3]$ (50% chance) $\to$ $[3]$ $\to$ $[]$
Adding them up, we get $\frac{1}{2}\cdot 4 + \frac{1}{4} \cdot 4 + \frac{1}{4} \cdot 3 = \frac{15}{4}$ . We see that $750000009 \cdot 4 \equiv 15 \pmod{1\,000\,000\,007}$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted