CF850F.Rainbow Balls

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You have a bag of balls of n different colors. You have a__i balls of the i-th color.

While there are at least two different colored balls in the bag, perform the following steps:

  • Take out two random balls without replacement one by one. These balls might be the same color.
  • Color the second ball to the color of the first ball. You are not allowed to switch the order of the balls in this step.
  • Place both balls back in the bag.
  • All these actions take exactly one second.

Let M = 109 + 7. It can be proven that the expected amount of time needed before you stop can be represented as a rational number , where P and Q are coprime integers and where Q is not divisible by M. Return the value .

你有一个装有 nn 种不同颜色球的袋子。第 ii 种颜色的球有 aia_i 个。

只要袋中至少存在两种不同颜色的球,就重复执行以下步骤:

  • 不放回地、依次随机取出两个球(这两个球颜色可能相同);
  • 将第二个球染成第一个球的颜色(此步骤中不允许交换两球的顺序);
  • 将两个球都放回袋中;
  • 上述所有操作恰好耗时一秒。

令 M=109+7M = 10^9 + 7。可以证明:在停止前所需时间的期望值可表示为一个有理数 ,其中 PP 与 QQ 互质,且 QQ 不被 MM 整除。请返回值 。

输入格式

The first line of input will contain a single integer n (1 ≤ n ≤ 2 500) — the number of colors.

The next line of input will contain n space separated integers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 105) — the number of balls of each color.

输入的第一行包含一个整数 nn(1 ≤ n ≤ 2 5001 ≤ n ≤ 2\,500)——颜色的种类数。

输入的第二行包含 nn 个用空格分隔的整数 a1, a2, ..., ana_1,\,a_2,\,...,\,a_n(1 ≤ ai ≤ 1051 ≤ a_i ≤ 10^5)——每种颜色的小球数量。

输出格式

Print a single integer, the answer to the problem.

输出一个整数,即该问题的答案。

输入输出样例

  • 输入#1

    2
    1 1

    输出#1

    1
  • 输入#2

    3
    1 2 3

    输出#2

    750000026

说明/提示

In the first sample, no matter what happens, the balls will become the same color after one step.

For the second sample, we have 6 balls. Let’s label the balls from 1 to 6, and without loss of generality, let’s say balls 1,2,3 are initially color 1, balls 4,5 are color 2, and ball 6 are color 3.

Here is an example of how these steps can go:

  • We choose ball 5 and ball 6. Ball 6 then becomes color 2.
  • We choose ball 4 and ball 5. Ball 5 remains the same color (color 2).
  • We choose ball 1 and ball 5. Ball 5 becomes color 1.
  • We choose ball 6 and ball 5. Ball 5 becomes color 2.
  • We choose ball 3 and ball 4. Ball 4 becomes color 1.
  • We choose ball 4 and ball 6. Ball 6 becomes color 1.
  • We choose ball 2 and ball 5. Ball 5 becomes color 1.

At this point, the game ends since all the balls are the same color. This particular sequence took 7 seconds.

It can be shown that the answer to this case is .

在第一个样例中,无论发生什么情况,经过一步操作后所有球都会变为同一种颜色。

在第二个样例中,我们有 6 个球。我们将这些球编号为 1 到 6;不失一般性,假设球 1、2、3 初始颜色为颜色 1,球 4、5 初始颜色为颜色 2,球 6 初始颜色为颜色 3。

以下是一个可能的操作过程示例:

  • 我们选择球 5 和球 6,于是球 6 变为颜色 2。
  • 我们选择球 4 和球 5,球 5 颜色保持不变(仍为颜色 2)。
  • 我们选择球 1 和球 5,于是球 5 变为颜色 1。
  • 我们选择球 6 和球 5,于是球 5 变为颜色 2。
  • 我们选择球 3 和球 4,于是球 4 变为颜色 1。
  • 我们选择球 4 和球 6,于是球 6 变为颜色 1。
  • 我们选择球 2 和球 5,于是球 5 变为颜色 1。

此时游戏结束,因为所有球颜色相同。该特定序列共耗时 7 秒。

可以证明,本情况的答案为 。

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

首页