AT_scpc2026_div2_e.Opening Magical Box

入门

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

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

题目描述

Lulu found a magical box containing treasure. The box has NN distinct spells cast on it, one of each type, and it can be opened only by dispelling all of them in the correct order. Lulu, a genius magician, has identified all NN types of spells on the box, but does not know the correct order in which they must be dispelled.

To open the box, Lulu attempts the following procedure.

  1. Lulu chooses one spell that is still cast on the box among the NN spells and tries to dispel it. When Lulu tries to dispel the ii-th spell, MiM_i magic power is consumed.

  2. If the attempted spell is the correct spell in the order, the dispelling succeeds. If it is not the correct spell in the order, the box returns to the state where all NN spells are cast on it. Lulu can immediately tell whether the dispelling attempt succeeded. The order required for dispelling the spells does not change.

  3. Once all NN spells are dispelled, the box opens.

Given NN and the magic power cost MiM_i of each spell, find the expected total amount of magic power Lulu will consume if Lulu opens the box using an optimal strategy. The correct order of spells is one of the N!N! possible orders, and all possible orders are equally likely.

露露发现了一个装有宝藏的魔法宝箱。宝箱上施加了 NN 种互不相同的咒语,每种各一个,且只有按正确顺序逐一解除全部咒语,宝箱才能打开。露露是一位天才魔法师,已识别出宝箱上的全部 NN 种咒语类型,但尚不清楚它们必须被解除的正确顺序。

为打开宝箱,露露采用如下尝试过程:

  1. 露露从当前仍作用于宝箱的 NN 个咒语中任选一个,尝试将其解除。当露露尝试解除第 ii 个咒语时,消耗 MiM_i 点魔法值。

  2. 若所选咒语恰好是当前所需解除的正确咒语(即处于正确顺序中的当前位置),则解除成功;否则,宝箱将重置回初始状态——即所有 NN 个咒语均重新施加于宝箱之上。露露能立即判断此次解除尝试是否成功。而咒语需被解除的正确顺序本身始终保持不变。

  3. 当全部 NN 个咒语均被成功解除后,宝箱开启。

给定 NN 及每个咒语的魔法值消耗 MiM_i,求露露采用最优策略打开宝箱时,所消耗的魔法值总量的期望值。所有 N!N! 种可能的正确咒语顺序等概率出现。

输入格式

The input is given from Standard Input in the following format:

NN
M1M_1 M2M_2 …\dots MNM_N

输入从标准输入中按以下格式给出:

NN
M1M_1 M2M_2 …\dots MNM_N

输出格式

Output the expected total amount of magic power Lulu will consume. An absolute or relative error of at most 10−610^{-6} is accepted.

输出Lulu将消耗的魔法能量的期望总量。允许的绝对或相对误差不超过 10−610^{-6}。

输入输出样例

  • 输入#1

    1
    10

    输出#1

    10
  • 输入#2

    2
    10 20

    输出#2

    35

说明/提示

表示言語

/ /

Constraints

  • 1≤N≤100 0001 \leq N \leq 100\,000
  • 1≤Mi≤100 0001 \leq M_i \leq 100\,000
  • All given numbers are integers.

表示语言

/ /

限制条件

  • 1≤N≤100 0001 \leq N \leq 100\,000
  • 1≤Mi≤100 0001 \leq M_i \leq 100\,000
  • 所有给定的数均为整数。

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

首页