AtCoder Regular Contest 162
D
Smallest Vertices
AtCoder
⌀ 2568
原题
← CE →
翻译中…

Problem Statement

翻译中…

In this problem, a rooted directed tree is a rooted tree where all edges are directed from the root to the leaves.

翻译中…

You are given a sequence of non-negative integers $d=(d_1,d_2,\ldots,d_N)$ with a sum of $N-1$.

翻译中…

Among the $N$-vertex rooted directed trees with vertex numbered $1$ to $N$ and vertex $1$ as the root, a good tree is one that satisfies the following condition:

翻译中…
  • the out-degree of vertex $i\ (1\leq i \leq N)$ is $d_i$.
翻译中…

Furthermore, for a vertex $v$ of a good tree, let $f(v)$ be the minimum vertex number of the vertices (including $v$) in the subtree rooted at vertex $v$, and $v$ is called a good vertex if it satisfies $f(v)=v$.

翻译中…

Find the sum of the numbers of good vertices for all good trees, modulo $998244353$.

翻译中…

Constraints

翻译中…
  • $2 \leq N \leq 500$
  • $0 \leq d_i \leq N-1$
  • $d_1 \geq 1$
  • $\sum_{i=1}^N d_i = N-1$
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N
d_1 d_2 \ldots d_N

翻译中…

Output

翻译中…

Print the answer.

翻译中…

样例

Input #1
4
2 0 1 0
Output #1
7
There are two good trees, as shown below. The blue vertices are good vertices. ![image](https://img.atcoder.jp/arc162/D-sample1-zFXKLnmt.png) For these trees, there are $4$ and $3$ good vertices, respectively, so the answer is $7$.
Input #2
10
3 1 0 0 2 0 1 2 0 0
Output #2
37542
题目信息
题号
arc162_d
时间限制
2 s
内存限制
1024 MB

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