#P2290. [HNOI2004] 树的计数

    ID: 1261 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>数学2004各省省选湖南组合数学排列组合

[HNOI2004] 树的计数

Description

Consider a tree with nn nodes, denoted v1,v2,,vnv_1, v_2, \ldots, v_n. The degree of node viv_i is given as did_i. How many distinct trees satisfy these conditions?

Input Format

The first line contains a positive integer nn, the number of nodes in the tree. The second line contains nn integers; the ii-th of them is did_i, the degree of node viv_i.

Output Format

Output the number of trees that satisfy the conditions.

4                     
2 1 2 1

2

Hint

Constraints: 1n1501 \le n \le 150. It is guaranteed that the number of valid trees does not exceed 101710^{17}.

Translated by ChatGPT 5