A11029 | An unavoidable detour for home
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
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.
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 one integer — the total number of different possible ways in which the towns are connected, modulo $10^{9}+7$ .
输入输出样例
输入 #1
4 3 2 3 2
输出 #1
1
输入 #2
5 2 3 3 2 2
输出 #2
2
输入 #3
5 2 2 2 2 2
输出 #3
2
输入 #4
20 2 2 2 2 3 2 3 2 2 2 2 2 2 2 2 2 2 3 3 2
输出 #4
82944
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$ .
In the second example, the following two structures satisfy the constraints.

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

C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted