Counting DFS Trees
InterviewTime limit1sMemory limit2048 MB
Count the distinct preorder depth sequences of trees with n nodes whose leaves all sit at depth K, then multiply f(A_i) for all queries modulo 998244353.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Prefix sum, Combinatorics
- Solved
- No attempts yet
문제
You are studying the Depth First Search (DFS) tree traversal algorithm. Consider a rooted tree of nodes, numbered from to , with depth (levels numbered from to ). The root, the node at depth , is node . All leaves are located at the same depth, that is, depth . Node has an array of children , which may be empty if is a leaf. The algorithm is written in pseudocode below.
DFS(u, depth):
let res be an empty array
append depth to res
for each v in c[u]:
let D be an array initialized with DFS(v, depth + 1)
for each x in D:
append x to res
return res
In the trees shown in the illustration, the return values of DFS(1, 1) are for the left tree and for the right tree.

Let be the number of distinct return values of DFS(1, 1) over all trees with nodes in which all leaves are at depth . You are given integers . Find the value of modulo .
입력
The first line contains two integers and (). The second line contains integers ().
출력
Print the value of modulo .