CF1854C.Expected Destruction

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You have a set SS of nn distinct integers between 11 and mm .

Each second you do the following steps:

  1. Pick an element xx in SS uniformly at random.
  2. Remove xx from SS .
  3. If x+1mx+1 \leq m and x+1x+1 is not in SS , add x+1x+1 to SS .

What is the expected number of seconds until SS is empty?

Output the answer modulo 10000000071\,000\,000\,007 .

Formally, let P=1000000007P = 1\,000\,000\,007 . It can be shown that the answer can be expressed as an irreducible fraction ab\frac{a}{b} , where aa and bb are integers and b≢0(modP)b \not \equiv 0 \pmod{P} . Output the integer equal to ab1modPa \cdot b^{-1} \bmod P . In other words, output an integer zz such that 0z<P0 \le z < P and zba(modP)z \cdot b \equiv a \pmod{P} .

输入格式

The first line contains two integers nn and mm ( 1nm5001 \leq n \leq m \leq 500 ) — the number of elements in the set SS and the upper bound on the value of the elements in SS .

The second line contains nn integers S1,S2,,SnS_1,\,S_2,\,\dots,\,S_n ( 1S1<S2<<Snm1 \leq S_1 < S_2 < \ldots < S_n \leq m ) — the elements of the set SS .

输出格式

Output a single integer — the expected number of seconds until SS is empty, modulo 10000000071\,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][1, 3] (50% chance) \to [1][1] \to [2][2] \to [3][3] \to [][]
  2. [1,3][1, 3] (50% chance) \to [2,3][2, 3] (50% chance) \to [2][2] \to [3][3] \to [][]
  3. [1,3][1, 3] (50% chance) \to [2,3][2, 3] (50% chance) \to [3][3] \to [][]

Adding them up, we get 124+144+143=154\frac{1}{2}\cdot 4 + \frac{1}{4} \cdot 4 + \frac{1}{4} \cdot 3 = \frac{15}{4} . We see that 750000009415(mod1000000007)750000009 \cdot 4 \equiv 15 \pmod{1\,000\,000\,007} .

首页