hdu-5635 LCP Array

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.