CF1854C.Expected Destruction

省选/NOI-

通过率:0%

时间限制:1.00s

内存限制:256MB

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+1≤mx+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 1 000 000 0071\,000\,000\,007.

Formally, let P=1 000 000 007P = 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 a⋅b−1 mod Pa \cdot b^{-1} \bmod P. In other words, output an integer zz such that 0≤z<P0 \le z \lt P and z⋅b≡a(modP)z \cdot b \equiv a \pmod{P}.

你有一个由 nn 个互不相同的整数组成的集合 SS,其中每个整数均在 11 到 mm 之间(含端点)。

每秒钟,你执行以下步骤:

  1. 在 SS 中均匀随机地选取一个元素 xx;
  2. 将 xx 从 SS 中移除;
  3. 若 x+1≤mx+1 \leq m 且 x+1∉Sx+1 \notin S,则将 x+1x+1 加入 SS。

求 SS 变为空集所需时间的期望值(单位:秒)。

请将答案对 1 000 000 0071\,000\,000\,007 取模后输出。

形式化地,令 P=1 000 000 007P = 1\,000\,000\,007。可以证明,该期望值可表示为既约分数 ab\frac{a}{b},其中 aa 和 bb 均为整数,且 b≢0(modP)b \not \equiv 0 \pmod{P}。请输出整数 a⋅b−1 mod Pa \cdot b^{-1} \bmod P。换言之,输出满足 0≤z<P0 \le z < P 且 z⋅b≡a(modP)z \cdot b \equiv a \pmod{P} 的整数 zz。

输入格式

The first line contains two integers nn and mm (1≤n≤m≤5001 \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 (1≤S1<S2<…<Sn≤m1 \leq S_1 \lt S_2 \lt \ldots \lt S_n \leq m) — the elements of the set SS.

第一行包含两个整数 nn 和 mm(1≤n≤m≤5001 \leq n \leq m \leq 500)—— 分别表示集合 SS 中的元素个数以及集合 SS 中元素值的上界。

第二行包含 nn 个整数 S1, S2, …, SnS_1,\,S_2,\,\dots,\,S_n(1≤S1<S2<…<Sn≤m1 \leq S_1 \lt S_2 \lt \ldots \lt S_n \leq m)—— 表示集合 SS 的元素。

输出格式

Output a single integer — the expected number of seconds until SS is empty, modulo 1 000 000 0071\,000\,000\,007.

输出一个整数——即 SS 变为空集所需的期望秒数,对 1 000 000 0071\,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 12⋅4+14⋅4+14⋅3=154\frac{1}{2}\cdot 4 + \frac{1}{4} \cdot 4 + \frac{1}{4} \cdot 3 = \frac{15}{4}. We see that 750000009⋅4≡15(mod1 000 000 007)750000009 \cdot 4 \equiv 15 \pmod{1\,000\,000\,007}.

对于测试 1,以下是所有可能的情形及其概率:

  1. [1,3][1, 3](50% 概率)→\to [1][1] →\to [2][2] →\to [3][3] →\to [][]
  2. [1,3][1, 3](50% 概率)→\to [2,3][2, 3](50% 概率)→\to [2][2] →\to [3][3] →\to [][]
  3. [1,3][1, 3](50% 概率)→\to [2,3][2, 3](50% 概率)→\to [3][3] →\to [][]

将它们相加,得到 12⋅4+14⋅4+14⋅3=154\frac{1}{2}\cdot 4 + \frac{1}{4} \cdot 4 + \frac{1}{4} \cdot 3 = \frac{15}{4}。我们发现 750000009⋅4≡15(mod1 000 000 007)750000009 \cdot 4 \equiv 15 \pmod{1\,000\,000\,007}。

输入解题思路,AI测评打分。不知道怎么写?

首页