#abc249h. Ex - Dye Color

Ex - Dye Color

Score : 600600 points

问题描述

设有 NN 个编号从 11NN 的球。最初,第 ii 个球被涂上了颜色 AiA_i

颜色用 11NN 之间的整数表示(包括 11NN)。

考虑重复执行以下操作,直到所有球的颜色变得相同。

  • 在包含 NN 个球的集合的所有 2N2^N 个子集(包括空集)中,均匀随机选择一个子集。设所选球的索引为 X1,X2,...,XKX_1, X_2, ..., X_K。接下来,通过从整数 (1,2,,N)(1,2,\dots,N) 中均匀随机选择 KK 个整数得到一个排列。设所选排列为 P=(P1,P2,,PK)P=(P_1,P_2,\dots,P_K)。对于满足 1iK1 \le i \le K 的每个整数 ii,将第 XiX_i 个球的颜色改为 PiP_i

求出执行操作次数的期望值,结果对 998244353998244353 取模。

这里所说的通过从整数 (1,2,,N)(1,2,\dots,N) 中选择 KK 个整数得到的排列是指一个包含 KK 个在 11NN 之间(包括 11NN)的互不相同的整数构成的序列。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are NN balls numbered 11 through NN. Initially, Ball ii is painted in Color AiA_i.

Colors are represented by integers between 11 and NN, inclusive.

Consider repeating the following operation until all the colors of the balls become the same.

  • There are 2N2^N subsets (including the empty set) of the set consisting of the NN balls; choose one of the subsets uniformly at random. Let X1,X2,...,XKX_1,X_2,...,X_K be the indices of the chosen balls. Next, choose a permutation obtained by choosing KK integers out of integers (1,2,,N)(1,2,\dots,N) uniformly at random. Let P=(P1,P2,,PK)P=(P_1,P_2,\dots,P_K) be the chosen permutation. For each integer ii such that 1iK1 \le i \le K, change the color of Ball XiX_i to PiP_i.

Find the expected value of number of operations, modulo 998244353998244353.

Here a permutation obtained by choosing KK integers out of integers (1,2,,N)(1,2,\dots,N) is a sequence of KK integers between 11 and NN, inclusive, whose elements are pairwise distinct.

Notes

We can prove that the sought expected value is always a rational number. Also, under the Constraints of this problem, when the value is represented by two coprime integers PP and QQ as PQ\frac{P}{Q}, we can prove that there exists a unique integer RR such that R×QP(mod 998244353)R \times Q \equiv P(\bmod\ 998244353) and 0R<9982443530 \le R < 998244353. Find this RR.

Constraints

  • 2N20002 \le N \le 2000
  • 1AiN1 \le A_i \le N
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \dots ANA_N

Output

Print the answer.

Sample Input 1

2
1 2

Sample Output 1

4

The operation is repeated until a subset of size 11 is chosen and the color of the ball is changed to the color of the ball not contained in the subset. The probability is $\displaystyle \frac{2}{4} \times \frac{1}{2}=\frac{1}{4}$, so the expected value is 44.

Sample Input 2

3
1 1 1

Sample Output 2

0

The operation is never performed, since the colors of the balls are already the same.

Sample Input 3

10
3 1 4 1 5 9 2 6 5 3

Sample Output 3

900221128

update @ 2024/3/10 10:40:16