LCP Array
Time limit:4000/2000 MS (java/others) Memory limit:131072/131072 K (java/others)
Total submission (s): 358 Accepted Submission (s): 102
Problem Descriptionpeter has a strings =s1s 2 sn , letSuffI= Sis I+1 sn Being the suffix start withI-th character ofs. Peter knows the LCP (longest common prefix) of each of the adjacent suffixes which denotes asAI=Lcp(suffi,suffi+1)(1≤i<n ).
Given the LCP array, Peter wants to know how many strings containing lowercase 中文版 letters only would satisfy the LCP a Rray. The answer may too large, just print it modulo 9+7.
Inputthere is multiple test cases. The first line of input contains an integerTindicating the number of test cases. For each test case:
The first line contains an integerN(2≤n≤10^5) -The length of the string. The second line containsn−1 Integers:a1,a2,.. . ,an−1 (0≤ai≤n) .
The sum of values of n in all test cases doesn ' t exceed 10^6.
Outputfor each test case output one integer denoting the answer. The answer must be printed modulo1e9+7.
Sample Input330 043 2 131 2
Sample OUTPUT16250260AC Code:
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace Std;
const int n=1e5+5;
Const long Long mod=1e9+7;
int n,a[n];
int main ()
{
int T;
scanf ("%d", &t);
while (t--)
{
scanf ("%d", &n);
for (int i=1;i<n;i++)
{
scanf ("%d", &a[i]);
}
a[n]=0;
int flag=1;
for (int i=1;i<n;i++)
{
if (A[i])
{
if (a[i]-a[i+1]!=1)
{
flag=0;
Break
}
}
}
if (!flag)
{
cout<< "0" << "\ n";
}
Else
{
int num=0;
for (int i=1;i<n;i++)
{
if (!a[i])
{
num++;
}
}
Long Long ans=26;
for (int i=0;i<num;i++)
{
Ans= (ans*25)%mod;
}
cout<<ans%mod<< "\ n";
}
}
return 0;
}
hdu-5635 LCP Array