F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

LCP Array

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 2018    Accepted Submission(s): 665


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
3 3 0 0 4 3 2 1 3 1 2
 

Sample Output
16250 26 0
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-26 05:58:41, Gzip enabled