Codeforces Round 418 (Div. 2)
E
An unavoidable detour for home
Codeforces
2600
原题
← D→
翻译中…

Those unwilling to return home from a long journey, will be affected by the oddity of the snail and lose their way. Mayoi, the oddity's carrier, wouldn't like this to happen, but there's nothing to do with this before a cure is figured out. For now, she would only like to know the enormous number of possibilities to be faced with if someone gets lost.

翻译中…

There are $*n*$ towns in the region, numbered from $1$ to $*n*$. The town numbered $1$ is called the capital. The traffic network is formed by bidirectional roads connecting pairs of towns. No two roads connect the same pair of towns, and no road connects a town with itself. The time needed to travel through each of the roads is the same. Lost travelers will not be able to find out how the towns are connected, but the residents can help them by providing the following facts:

翻译中…
  • Starting from each town other than the capital, the shortest path (i.e. the path passing through the minimum number of roads) to the capital exists, and is unique;
  • Let $*l*_{*i*}$ be the number of roads on the shortest path from town $*i*$ to the capital, then $*l*_{*i*} ≥ *l*_{*i* - 1}$ holds for all $2 ≤ *i* ≤ *n*$;
  • For town $*i*$, the number of roads connected to it is denoted by $*d*_{*i*}$, which equals either $2$ or $3$.
翻译中…

You are to count the number of different ways in which the towns are connected, and give the answer modulo $10^{9} + 7$. Two ways of connecting towns are considered different if a pair $(*u*, *v*)$ ($1 ≤ *u*, *v* ≤ *n*$) exists such there is a road between towns $*u*$ and $*v*$ in one of them but not in the other.

翻译中…

Input

翻译中…

The first line of input contains a positive integer $*n*$ ($3 ≤ *n* ≤ 50$) — the number of towns.

翻译中…

The second line contains $*n*$ space-separated integers $*d*_{1}, *d*_{2}, ..., *d*_{*n*}$ ($2 ≤ *d*_{*i*} ≤ 3$) — the number of roads connected to towns $1, 2, ..., *n*$, respectively. It is guaranteed that the sum of $*d*_{*i*}$ over all $*i*$ is even.

翻译中…

Output

翻译中…

Output one integer — the total number of different possible ways in which the towns are connected, modulo $10^{9} + 7$.

翻译中…

Note

翻译中…

In the first example, the following structure is the only one to satisfy the constraints, the distances from towns $2, 3, 4$ to the capital are all $1$.

翻译中…

image

翻译中…

In the second example, the following two structures satisfy the constraints.

翻译中…

image

翻译中…

样例

Input #1
4
3 2 3 2
Output #1
1
InputCopy OutputCopy
Input #2
5
2 3 3 2 2
Output #2
2
InputCopy OutputCopy
Input #3
5
2 2 2 2 2
Output #3
2
InputCopy OutputCopy
Input #4
20
2 2 2 2 3 2 3 2 2 2 2 2 2 2 2 2 2 3 3 2
Output #4
82944
InputCopy OutputCopy
题目信息
题号
814E
时间限制
3 s
内存限制
256 MB
标签
组合数学
动态规划
图论
最短路

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