201045: [AtCoder]ARC104 F - Visibility Sequence

Memory Limit:1024 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $1000$ points

Problem Statement

There are $N$ buildings under construction arranged in a row, numbered $1, 2, \ldots, N$ from left to right.

Given is an integer sequence $X$ of length $N$. The height of Building $i$, $H_i$, can be one of the integers between $1$ and $X_i$ (inclusive).

For each $i$ such that $1 \leq i \leq N$, let us define $P_i$ as follows:

  • If there is an integer $j (1 \leq j < i)$ such that $H_j > H_i$, $P_i$ is the maximum such $j$. Otherwise, $P_i$ is $-1$.

Considering all possible combinations of the buildings' heights, find the number of integer sequences that $P$ can be, modulo $1000000007$.

Constraints

  • $1 \leq N \leq 100$
  • $1 \leq X_i \leq 10^5$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$
$X_1$ $X_2$ $\cdots$ $X_N$

Output

Print the number of integer sequences that $P$ can be when all possible combinations of the buildings' heights are considered, modulo $1000000007$.


Sample Input 1

3
3 2 1

Sample Output 1

4

We have six candidates for $H$, as follows:

  • $H = (1, 1, 1)$, for which $P$ is $(-1, -1, -1)$;
  • $H = (1, 2, 1)$, for which $P$ is $(-1, -1, 2)$;
  • $H = (2, 1, 1)$, for which $P$ is $(-1, 1, 1)$;
  • $H = (2, 2, 1)$, for which $P$ is $(-1, -1, 2)$;
  • $H = (3, 1, 1)$, for which $P$ is $(-1, 1, 1)$;
  • $H = (3, 2, 1)$, for which $P$ is $(-1, 1, 2)$.

Thus, there are four integer sequences that $P$ can be: $(-1, -1, -1), (-1, -1, 2), (-1, 1, 1)$, and $(-1, 1, 2)$.


Sample Input 2

3
1 1 2

Sample Output 2

1

We have two candidates for $H$, as follows:

  • $H = (1, 1, 1)$, for which $P$ is $(-1, -1, -1)$;
  • $H = (1, 1, 2)$, for which $P$ is $(-1, -1, -1)$.

Thus, there is one integer sequence that $P$ can be.


Sample Input 3

5
2 2 2 2 2

Sample Output 3

16

Sample Input 4

13
3 1 4 1 5 9 2 6 5 3 5 8 9

Sample Output 4

31155

Input

题意翻译

有一排共 $n$ 栋房子,同时给出一个长为 $n$ 的序列 $X$,第 $i$ 栋房子的高度 $H_i\in[1,X_i]$ 且为整数。 按照房屋的高度生成一个序列 $P$,其中 $P_i$ 为 $i$ 左边第一个比它高的房子的编号,若不存在,则为 $-1$。 求有多少种本质不同的 $P$,对 $10^9+7$ 取模。

加入题单

算法标签: