#abc272h. Ex - Flipping Coins 2
Ex - Flipping Coins 2
Score : points
问题描述
设有编号为 的 枚硬币排成一行。最初,所有硬币均为正面朝上。同时,你得到了一个长度为 的由 到 的整数组成的序列 。
Snuke 将以等概率选择一个包含 的排列 ,并执行 次操作。在第 次 操作中,
- 他会翻转 枚硬币:编号为 、、 和 的硬币。
经过 次操作后,Snuke 从他母亲那里得到 日元(日本货币),其中 是正面朝上的硬币数量。
求 Snuke 将会收到的钱数的期望值,模 。
模 下期望值的定义
在这个问题中,可以证明所求期望值始终是一个有理数。此外,在本题的约束条件下,若所求期望值表示为不可约分数 ,则保证 不被 整除。
此时,存在一个介于 和 之间的整数 ,满足 ,且这个 唯一确定。找出这样的 。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
coins numbered are arranged in a row. Initially, all coins are face up. Also, you are given a sequence of length consisting of integers between and .
Snuke will choose a permutation of at equal probability and perform operations. In the -th operation,
- he flips coins: coin , coin , , and coin .
After the operations, Snuke receives yen (the currency in Japan) from his mother, where is the number of face-up coins.
Find the expected value, modulo , of the money Snuke will receive.
Definition of expected value modulo
In this problem, we can prove that the sought expected value is always a rational number. Moreover, under the Constraints of this problem, when the sought expected value is represented as an irreducible fraction , it is guaranteed that is indivisible by .
Then, an integer between and such that is uniquely determined. Find such .
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
2
0 1
Sample Output 1
1
can be either or .
- If is chosen as :
In the first operation, coin is flipped, and in the second operation, coin and coin are flipped. One coin, coin , results in being face up, so he receives yen.
- If is chosen as :
In the first operation, coin and coin are flipped, and in the second operation, coin is flipped. One coin, coin , results in being face up, so he receives yen.
Therefore, the expected value of the money he receives is yen.
Sample Input 2
4
3 1 1 2
Sample Output 2
665496237
Print the expected value modulo .
update @ 2024/3/10 11:29:18