← Home
write a go solution for Description:
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<=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 a/b, where a and b are integers and bnotequiv0pmodP. Output the integer equal to a*b^-1bmodP. In other words, output an integer z such that 0<=z<P and z*bequivapmodP.

Input Format:
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 S_1,,S_2,,...,,S_n (1<=S_1<S_2<ldots<S_n<=m) — the elements of the set S.

Output Format:
Output a single integer — the expected number of seconds until S is empty, modulo 1,000,000,007.

Note:
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 1/2*4+1/4*4+1/4*3=15/4. We see that 750000009*4equiv15pmod1,000,000,007.. Output only the code with no comments, explanation, or additional text.