CF1854C.Expected Destruction
省选/NOI-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have a set S of n distinct integers between 1 and m.
Each second you do the following steps:
- Pick an element x in S uniformly at random.
- Remove x from S.
- If x+1≤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 1000000007.
Formally, let P=1000000007. It can be shown that the answer can be expressed as an irreducible fraction ba, where a and b are integers and b≡0(modP). Output the integer equal to a⋅b−1modP. In other words, output an integer z such that 0≤z<P and z⋅b≡a(modP).
你有一个由 n 个互不相同的整数组成的集合 S,其中每个整数均在 1 到 m 之间(含端点)。
每秒钟,你执行以下步骤:
- 在 S 中均匀随机地选取一个元素 x;
- 将 x 从 S 中移除;
- 若 x+1≤m 且 x+1∈/S,则将 x+1 加入 S。
求 S 变为空集所需时间的期望值(单位:秒)。
请将答案对 1000000007 取模后输出。
形式化地,令 P=1000000007。可以证明,该期望值可表示为既约分数 ba,其中 a 和 b 均为整数,且 b≡0(modP)。请输出整数 a⋅b−1modP。换言之,输出满足 0≤z<P 且 z⋅b≡a(modP) 的整数 z。
输入格式
The first line contains two integers n and m (1≤n≤m≤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 S1,S2,…,Sn (1≤S1<S2<…<Sn≤m) — the elements of the set S.
第一行包含两个整数 n 和 m(1≤n≤m≤500)—— 分别表示集合 S 中的元素个数以及集合 S 中元素值的上界。
第二行包含 n 个整数 S1,S2,…,Sn(1≤S1<S2<…<Sn≤m)—— 表示集合 S 的元素。
输出格式
Output a single integer — the expected number of seconds until S is empty, modulo 1000000007.
输出一个整数——即 S 变为空集所需的期望秒数,对 1000000007 取模。
输入输出样例
输入#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,3] (50% chance) → [1] → [2] → [3] → []
- [1,3] (50% chance) → [2,3] (50% chance) → [2] → [3] → []
- [1,3] (50% chance) → [2,3] (50% chance) → [3] → []
Adding them up, we get 21⋅4+41⋅4+41⋅3=415. We see that 750000009⋅4≡15(mod1000000007).
对于测试 1,以下是所有可能的情形及其概率:
- [1,3](50% 概率)→ [1] → [2] → [3] → []
- [1,3](50% 概率)→ [2,3](50% 概率)→ [2] → [3] → []
- [1,3](50% 概率)→ [2,3](50% 概率)→ [3] → []
将它们相加,得到 21⋅4+41⋅4+41⋅3=415。我们发现 750000009⋅4≡15(mod1000000007)。
输入解题思路,AI测评打分。不知道怎么写?