A9863 | Progress Monitoring
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Programming teacher Dmitry Olegovich is going to propose the following task for one of his tests for students:
You are given a tree $T$ with $n$ vertices, specified by its adjacency matrix $a[1...\ n,1...\ n]$ . What is the output of the following pseudocode?
Two trees with $n$ vertices are called different if their adjacency matrices $a_{1}$ and $a_{2}$ are different, i. e. there exists a pair $(i,j)$ , such that $1<=i,j<=n$ and $a_{1}[i][j]≠a_{2}[i][j]$ .
You are given a tree $T$ with $n$ vertices, specified by its adjacency matrix $a[1...\ n,1...\ n]$ . What is the output of the following pseudocode?
<br></br>used[1 ... n] = {0, ..., 0};<br></br><br></br>procedure dfs(v):<br></br> print v;<br></br> used[v] = 1;<br></br> for i = 1, 2, ..., n:<br></br> if (a[v][i] == 1 and used[i] == 0):<br></br> dfs(i);<br></br><br></br>dfs(1);<br></br>In order to simplify the test results checking procedure, Dmitry Olegovich decided to create a tree $T$ such that the result is his favorite sequence $b$ . On the other hand, Dmitry Olegovich doesn't want to provide students with same trees as input, otherwise they might cheat. That's why Dmitry Olegovich is trying to find out the number of different trees $T$ such that the result of running the above pseudocode with $T$ as input is exactly the sequence $b$ . Can you help him?Two trees with $n$ vertices are called different if their adjacency matrices $a_{1}$ and $a_{2}$ are different, i. e. there exists a pair $(i,j)$ , such that $1<=i,j<=n$ and $a_{1}[i][j]≠a_{2}[i][j]$ .
输入格式
The first line contains the positive integer $n$ ( $1<=n<=500$ ) — the length of sequence $b$ .
The second line contains $n$ positive integers $b_{1},b_{2},...,b_{n}$ ( $1<=b_{i}<=n$ ). It is guaranteed that $b$ is a permutation, or in other words, each of the numbers $1,2,...,n$ appears exactly once in the sequence $b$ . Also it is guaranteed that $b_{1}=1$ .
The second line contains $n$ positive integers $b_{1},b_{2},...,b_{n}$ ( $1<=b_{i}<=n$ ). It is guaranteed that $b$ is a permutation, or in other words, each of the numbers $1,2,...,n$ appears exactly once in the sequence $b$ . Also it is guaranteed that $b_{1}=1$ .
输出格式
Output the number of trees satisfying the conditions above modulo $10^{9}+7$ .
输入输出样例
输入 #1
3 1 2 3
输出 #1
2
输入 #2
3 1 3 2
输出 #2
1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted