Codeforces Round 1064 (Div. 1)
B
Marble Council
Codeforces
1900
原题
← AC →
翻译中…

You are given a multiset $a$, which consists of $n$ integers $a_1,a_2,\ldots,a_n$. You would like to generate a new multiset $s$ through the following procedure:

翻译中…
  • Partition $a$ into any number of non-empty multisets $x_1,x_2,\ldots,x_k$, such that each element of $a$ belongs to exactly one of these multisets.
  • Initially, $s$ is empty. From each $x_i$, choose one of its modes$^{\text{∗}}$ and insert it into $s$.
翻译中…

Please count the number of different multisets $s$ that can be generated through the procedure, modulo $998\,244\,353$.

翻译中…

Please note that the number of different multisets is counted, which means that the order of elements does not matter. However, the count of each element does matter, i.e. $\{1,1,2\},\{1,2\},\{1,1,2,2\}$ are all considered different.

翻译中…

$^{\text{∗}}$The mode of a multiset is defined as the element which appears the most; if several elements are tied as the maximum, then all of them are considered modes.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 5000$). The description of the test cases follows.

翻译中…

The first line of each test case contains a single integer $n$ ($1\le n\le5000$) — the size of multiset $a$.

翻译中…

The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1\le a_i\le n$).

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $5000$.

翻译中…

Output

翻译中…

For each test case, print one line containing a single integer — the number of different multisets you can obtain, modulo $998\,244\,353$.

翻译中…

Note

翻译中…

In the first test case, any non-empty subset of $\{1,2,3\}$ can be achieved, for a total of $7$ multisets.

翻译中…

In the third test case, we can generate $4$ different multisets:

翻译中…
  • Partition the elements into set $\{1,2,2\}$, resulting in multiset $\{2\}$.
  • Partition the elements into sets $\{1,2\},\{2\}$, resulting in multiset $\{2,2\}$.
  • Partition the elements into sets $\{1\},\{2,2\}$, resulting in multiset $\{1,2\}$.
  • Partition the elements into sets $\{1\},\{2\},\{2\}$, resulting in multiset $\{1,2,2\}$.
翻译中…

It can be proven that no other multisets are possible.

翻译中…

样例

Input #1
5
3
1 2 3
3
1 1 1
3
1 2 2
10
1 1 1 1 2 2 2 3 3 4
10
1 1 1 2 2 2 3 3 3 4
Output #1
7
3
4
111
126
InputCopy OutputCopy
题目信息
题号
2165B
时间限制
2 s
内存限制
512 MB
标签
动态规划
数学
排序

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。