Visibility Sequence

AtCoder
IDarc104_f
Time2000ms
Memory256MB
Difficulty
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$ [samples]
Samples
Input #1
3
3 2 1
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)$.
Input #2
3
1 1 2
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.
Input #3
5
2 2 2 2 2
Output #3
16
Input #4
13
3 1 4 1 5 9 2 6 5 3 5 8 9
Output #4
31155
API Response (JSON)
{
  "problem": {
    "name": "Visibility Sequence",
    "description": {
      "content": "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 o",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc104_f"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There are $N$ buildings under construction arranged in a row, numbered $1, 2, \\ldots, N$ from left to right.\nGiven is an integer sequence $X$ of length $N$. The height of Building $i$, $H_i$, can be o...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments