#P6132. [集训队互测 2019] 简单计数

    ID: 5111 远端评测题 7000ms 512MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>数学2019WC/CTSC/集训队O2优化矩阵加速,矩阵优化组合数学生成函数快速傅里叶变换 FFT

[集训队互测 2019] 简单计数

Description

Legend says that a long, long time ago, there was a labeled directed acyclic graph (DAG) with nn vertices. Each edge has a color, which is one of kk different colors. The graph satisfies the following properties:

  • Each vertex has at most 11 outgoing edge.
  • The in-degree of each vertex belongs to the set SS.

For some reason, you want to know how many such graphs there are. Since the number may be huge, output the answer modulo 998244353998244353.

Two graphs are different if and only if there exists a directed edge from some vertex aa to some vertex bb that appears in exactly one of the two graphs, or appears in both graphs but with different colors.

Input Format

The first line contains three positive integers n,k,Sn, k, |S|.
The second line contains S|S| distinct non-negative integers in increasing order, representing the elements of the set SS.

Output Format

Output one integer in [0,998244352][0,998244352], the number of graphs satisfying the conditions modulo 998244353998244353.

3 1 2
0 1
13
8 2 3
0 2 3
7497953
3000 2 3
0 1 3
500207304
10000000 3 2
0 3
238588124
876543210 233 4
0 1 2 3
467638557

Hint

[Explanation for Sample 1]
There are 1313 graphs satisfying the conditions. Here aba \to b denotes a directed edge from aa to bb:

  1. No edges.
  2. 121 \to 2.
  3. 212 \to 1.
  4. 131 \to 3.
  5. 313 \to 1.
  6. 232 \to 3.
  7. 323 \to 2.
  8. 1231 \to 2 \to 3.
  9. 1321 \to 3 \to 2.
  10. 2132 \to 1 \to 3.
  11. 2312 \to 3 \to 1.
  12. 3123 \to 1 \to 2.
  13. 3213 \to 2 \to 1.

[Constraints]
The testdata is divided into 77 subtasks.

  • Subtask 11 (55 points): n8n \leq 8.
  • Subtask 22 (1010 points): n5000n \leq 5000.
  • Subtask 33 (3030 points): n105n \leq 10^5.
  • Subtask 44 (2020 points): n107n \leq 10^7.
  • Subtask 55 (1515 points): n108n \leq 10^8.
  • Subtask 66 (1010 points): S={0,1}S=\{0,1\}.
  • Subtask 77 (1010 points): no special constraints.

For 100%100\% of the testdata, 1n9×1081 \le n \le 9 \times 10^8 , 1k1071 \le k \le 10^7, SS \neq \varnothing, and S{0,1,2,3}S \subseteq \{0,1,2,3\}.

By: fjzzq2002
Source: CTT Mutual Test 2019 Day 5.

Input Format

The first line contains three positive integers n,k,Sn, k, |S|.
The second line contains S|S| distinct non-negative integers in increasing order, representing the elements of the set SS.

Output Format

Output one integer in [0,998244352][0,998244352], the number of graphs satisfying the conditions modulo 998244353998244353.

Hint

[Explanation for Sample 1]
There are 1313 graphs satisfying the conditions. Here aba \to b denotes a directed edge from aa to bb:

  1. No edges.
  2. 121 \to 2.
  3. 212 \to 1.
  4. 131 \to 3.
  5. 313 \to 1.
  6. 232 \to 3.
  7. 323 \to 2.
  8. 1231 \to 2 \to 3.
  9. 1321 \to 3 \to 2.
  10. 2132 \to 1 \to 3.
  11. 2312 \to 3 \to 1.
  12. 3123 \to 1 \to 2.
  13. 3213 \to 2 \to 1.

[Constraints]
The testdata is divided into 77 subtasks.

  • Subtask 11 (55 points): n8n \leq 8.
  • Subtask 22 (1010 points): n5000n \leq 5000.
  • Subtask 33 (3030 points): n105n \leq 10^5.
  • Subtask 44 (2020 points): n107n \leq 10^7.
  • Subtask 55 (1515 points): n108n \leq 10^8.
  • Subtask 66 (1010 points): S={0,1}S=\{0,1\}.
  • Subtask 77 (1010 points): no special constraints.

For 100%100\% of the testdata, 1n9×1081 \le n \le 9 \times 10^8 , 1k1071 \le k \le 10^7, SS \neq \varnothing, and S{0,1,2,3}S \subseteq \{0,1,2,3\}.

By: fjzzq2002
Source: CTT Mutual Test 2019 Day 5.

Translated by ChatGPT 5