![]() |
||||||||||
|
||||||||||
LCP ArrayTime Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 2021 Accepted Submission(s): 667 Problem Description Peter has a string $s=s_{1}s_{2}...s_{n}$, let $\text{suff}_i =s_{i}s_{i+1}...s_{n}$ be the suffix start with $i$-th character of $s$. Peter knows the lcp (longest common prefix) of each two adjacent suffixes which denotes as $a_i = \text{lcp}(\text{suff}_i, \text{suff}_{i+1}) \quad (1 \le i < n$). Given the lcp array, Peter wants to know how many strings containing lowercase English letters only will satisfy the lcp array. The answer may be too large, just print it modulo $10^9 + 7$. Input There are multiple test cases. The first line of input contains an integer $T$ indicating the number of test cases. For each test case: The first line contains an integer $n$ ($2 \le n \le 10^5)$ -- the length of the string. The second line contains $n - 1$ integers: $a_1,a_2,...,a_{n-1}$ $(0 \le a_i \le n)$. The sum of values of $n$ in all test cases doesn't exceed $10^6$. Output For each test case output one integer denoting the answer. The answer must be printed modulo $10^9+7$. Sample Input
Sample Output
Source | ||||||||||
|