CF1740F.Conditional Mix

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

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

题目描述

Pak Chanek is given an array aa of nn integers. For each ii (1≤i≤n1 \leq i \leq n), Pak Chanek will write the one-element set ai{a_i} on a whiteboard.

After that, in one operation, Pak Chanek may do the following:

  1. Choose two different sets SS and TT on the whiteboard such that S∩T=∅S \cap T = \varnothing (SS and TT do not have any common elements).
  2. Erase SS and TT from the whiteboard and write S∪TS \cup T (the union of SS and TT) onto the whiteboard.

After performing zero or more operations, Pak Chanek will construct a multiset MM containing the sizes of all sets written on the whiteboard. In other words, each element in MM corresponds to the size of a set after the operations.

How many distinct†^\dagger multisets MM can be created by this process? Since the answer may be large, output it modulo 998 244 353998\,244\,353.

†^\dagger Multisets BB and CC are different if and only if there exists a value kk such that the number of elements with value kk in BB is different than the number of elements with value kk in CC.

Pak Chanek 被给定一个包含 nn 个整数的数组 aa。对于每个 ii(1≤i≤n1 \leq i \leq n),Pak Chanek 将在黑板上写下仅含一个元素的集合 {ai}\{a_i\}。

此后,每次操作中,Pak Chanek 可执行以下步骤:

  1. 在黑板上选择两个互不相交的集合 SS 和 TT(即满足 S∩T=∅S \cap T = \varnothing);
  2. 将 SS 和 TT 从黑板上擦除,并将它们的并集 S∪TS \cup T 写回黑板。

在执行零次或多次上述操作后,Pak Chanek 将构造一个多重集 MM,其中包含黑板上所有剩余集合的大小。换言之,MM 中的每个元素对应一次操作结束后某个集合的大小。

通过该过程,总共能构造出多少个互不相同†^\dagger 的多重集 MM?由于答案可能很大,请对 998 244 353998\,244\,353 取模输出。

†^\dagger 多重集 BB 与 CC 被视为不同,当且仅当存在某个值 kk,使得 kk 在 BB 中的出现次数与在 CC 中的出现次数不同。

输入格式

The first line contains a single integer nn (1≤n≤20001 \le n \le 2000).

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤n1 \leq a_i \leq n).

第一行包含一个整数 nn(1≤n≤20001 \le n \le 2000)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n(1≤ai≤n1 \leq a_i \leq n)。

输出格式

Output the number of distinct multisets MM modulo 998 244 353998\,244\,353.

输出不同的多重集 MM 的数量,对 998 244 353998\,244\,353 取模。

输入输出样例

  • 输入#1

    6
    1 1 2 1 4 3

    输出#1

    7
  • 输入#2

    7
    3 5 4 3 7 4 5

    输出#2

    11

说明/提示

In the first example, the possible multisets MM are 1,1,1,1,1,1{1,1,1,1,1,1}, 1,1,1,1,2{1,1,1,1,2}, 1,1,1,3{1,1,1,3}, 1,1,2,2{1,1,2,2}, 1,1,4{1,1,4}, 1,2,3{1,2,3}, and 2,2,2{2,2,2}.

As an example, let's consider a possible sequence of operations.

  1. In the beginning, the sets are 1{1}, 1{1}, 2{2}, 1{1}, 4{4}, and 3{3}.
  2. Do an operation on sets 1{1} and 3{3}. Now, the sets are 1{1}, 1{1}, 2{2}, 4{4}, and 1,3{1,3}.
  3. Do an operation on sets 2{2} and 4{4}. Now, the sets are 1{1}, 1{1}, 1,3{1,3}, and 2,4{2,4}.
  4. Do an operation on sets 1,3{1,3} and 2,4{2,4}. Now, the sets are 1{1}, 1{1}, and 1,2,3,4{1,2,3,4}.
  5. The multiset MM that is constructed is 1,1,4{1,1,4}.

在第一个例子中,可能的多重集 MM 有:1,1,1,1,1,1{1,1,1,1,1,1}、1,1,1,1,2{1,1,1,1,2}、1,1,1,3{1,1,1,3}、1,1,2,2{1,1,2,2}、1,1,4{1,1,4}、1,2,3{1,2,3} 和 2,2,2{2,2,2}。

举个例子,我们考虑一种可能的操作序列:

  1. 初始时,各集合为 1{1}、1{1}、2{2}、1{1}、4{4} 和 3{3}。
  2. 对集合 1{1} 和 3{3} 执行一次操作。此时各集合变为 1{1}、1{1}、2{2}、4{4} 和 1,3{1,3}。
  3. 对集合 2{2} 和 4{4} 执行一次操作。此时各集合变为 1{1}、1{1}、1,3{1,3} 和 2,4{2,4}。
  4. 对集合 1,3{1,3} 和 2,4{2,4} 执行一次操作。此时各集合变为 1{1}、1{1} 和 1,2,3,4{1,2,3,4}。
  5. 最终构造出的多重集 MM 为 1,1,4{1,1,4}。

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

首页