

Time Limit: 2 sec / Memory Limit: 1024 MB
配点 : 点
問題文
この問題では、根付き有向木と言った際には全ての辺が根から葉の方向に向き付けられた根付き木を指すものとします。
総和が であるような非負整数列 が与えられます。
頂点に から の番号がついた、頂点 を根とする 頂点の根付き有向木のうち、以下の条件を満たすものを良い木と呼びます。
- 頂点 の出次数は
さらに、良い木の頂点 に対して、 を「頂点 の部分木に含まれる頂点( 含む)の頂点番号の最小値」と定め、 を満たす頂点を良い頂点と呼びます。
良い木全てに対する良い頂点の個数の総和を で割ったあまりを求めてください。
制約
- 入力される数値は全て整数
入力
入力は以下の形式で標準入力から与えられる。
出力
答えを出力せよ。
入力例 1Copy
4 2 0 1 0
出力例 1Copy
7
良い木は以下の 通りあります。青く塗られた頂点は良い頂点です。
それぞれについて良い頂点は 個、 個なので答えは です。
入力例 2Copy
10 3 1 0 0 2 0 1 2 0 0
出力例 2Copy
37542
Score : points
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 with a sum of .
Among the -vertex rooted directed trees with vertex numbered to and vertex as the root, a good tree is one that satisfies the following condition:
- the out-degree of vertex is .
Furthermore, for a vertex of a good tree, let be the minimum vertex number of the vertices (including ) in the subtree rooted at vertex , and is called a good vertex if it satisfies .
Find the sum of the numbers of good vertices for all good trees, modulo .
Constraints
- All input values are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1Copy
4 2 0 1 0
Sample Output 1Copy
7
There are two good trees, as shown below. The blue vertices are good vertices.
For these trees, there are and good vertices, respectively, so the answer is .
Sample Input 2Copy
10 3 1 0 0 2 0 1 2 0 0
Sample Output 2Copy
37542