CF509F.Progress Monitoring

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Programming teacher Dmitry Olegovich is going to propose the following task for one of his tests for students:

You are given a tree TT with nn vertices, specified by its adjacency matrix a[1... n,1... n]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 TT such that the result is his favorite sequence bb . 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 TT such that the result of running the above pseudocode with TT as input is exactly the sequence bb . Can you help him?

Two trees with nn vertices are called different if their adjacency matrices a1a_{1} and a2a_{2} are different, i. e. there exists a pair (i,j)(i,j) , such that 1<=i,j<=n1<=i,j<=n and a1[i][j]a2[i][j]a_{1}[i][j]≠a_{2}[i][j] .

输入格式

The first line contains the positive integer nn ( 1<=n<=5001<=n<=500 ) — the length of sequence bb .

The second line contains nn positive integers b1,b2,...,bnb_{1},b_{2},...,b_{n} ( 1<=bi<=n1<=b_{i}<=n ). It is guaranteed that bb is a permutation, or in other words, each of the numbers 1,2,...,n1,2,...,n appears exactly once in the sequence bb . Also it is guaranteed that b1=1b_{1}=1 .

输出格式

Output the number of trees satisfying the conditions above modulo 109+710^{9}+7 .

输入输出样例

  • 输入#1

    3
    1 2 3
    

    输出#1

    2
    
  • 输入#2

    3
    1 3 2
    

    输出#2

    1
    
首页