CF1854C.Expected Destruction
普及/提高-
通过率:0%
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) .
输入格式
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 .
输出格式
Output a single integer — the expected number of seconds until S is empty, modulo 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) .