302627: CF509F. Progress Monitoring

Memory Limit:256 MB Time Limit:1 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Progress Monitoring

题意翻译

### 题面翻译 编程老师$Dmitry Olegovich$(以下简称小$D$)准备在一次考试中出以下题目: **以邻接矩阵的方式给定一颗树,求下面这段伪代码的输出结果**。 ``` used[1 ... n] = {0, ..., 0}; procedure dfs(v): print v; used[v] = 1; for i = 1, 2, ..., n: if (a[v][i] == 1 and used[i] == 0): dfs(i); dfs(1); ``` 为了简化测试结果的检查过程 ~~(其实就是懒)~~ ,小 $D$ 决定创建一棵树 $T$ ,使得结果是他最喜欢的序列 $b$ 。不过,小 $D$ 不想为学生用相同的树作为输入(这意味着他们可能会作弊)。**所以小 $D$ 试图找出不同的树 $T$ 的数量,以便以 $T$ 作为输入运行上述伪代码的结果恰好是序列 $b$ ,答案对$10 ^9+7$取模**。 (两棵树“不同”的定义:它们的邻接矩阵不相同) ### 题面简述 见题面翻译中加粗部分。 ### 输入格式: 第一行一个整数 $n$,代表题目中序列 $b$ 的长度。 第二行 $n$ 个整数,表示序列 $b$(题目确保这是一个$1 \sim n$的排列,而且 $b_1=1$)。 ### 输出格式 一行一个整数表示答案,意思如题面所述。 ### 数据范围 $1\le n \le 500$

题目描述

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? `<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 $ .

输出格式


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

Input

题意翻译

### 题面翻译 编程老师$Dmitry Olegovich$(以下简称小$D$)准备在一次考试中出以下题目: **以邻接矩阵的方式给定一颗树,求下面这段伪代码的输出结果**。 ``` used[1 ... n] = {0, ..., 0}; procedure dfs(v): print v; used[v] = 1; for i = 1, 2, ..., n: if (a[v][i] == 1 and used[i] == 0): dfs(i); dfs(1); ``` 为了简化测试结果的检查过程 ~~(其实就是懒)~~ ,小 $D$ 决定创建一棵树 $T$ ,使得结果是他最喜欢的序列 $b$ 。不过,小 $D$ 不想为学生用相同的树作为输入(这意味着他们可能会作弊)。**所以小 $D$ 试图找出不同的树 $T$ 的数量,以便以 $T$ 作为输入运行上述伪代码的结果恰好是序列 $b$ ,答案对$10 ^9+7$取模**。 (两棵树“不同”的定义:它们的邻接矩阵不相同) ### 题面简述 见题面翻译中加粗部分。 ### 输入格式: 第一行一个整数 $n$,代表题目中序列 $b$ 的长度。 第二行 $n$ 个整数,表示序列 $b$(题目确保这是一个$1 \sim n$的排列,而且 $b_1=1$)。 ### 输出格式 一行一个整数表示答案,意思如题面所述。 ### 数据范围 $1\le n \le 500$

加入题单

上一题 下一题 算法标签: