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 Description
Peter has a string s=s1s2...sn, let suffi=sisi+1...sn 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 ai=lcp(suffi,suffi+1)(1≤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 109+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≤n≤10^5) -- the length of the string. The second line contains n−1 integers: a1,a2,...,an−1 (0≤ai≤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 1e9+7.
 
Sample Input
3
3
0 0
4
3 2 1
3
1 2
 
Sample Output
16250
26
0
AC代码:

#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的更多相关文章

  1. hdu 5635 LCP Array(BC第一题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5635 LCP Array Time Limit: 4000/2000 MS (Java/Others) ...

  2. HDU 5635 ——LCP Array ——————【想法题】

    LCP Array Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  3. LCP Array(思维)

    LCP Array Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Tota ...

  4. HDU 5164Matching on Array(AC自动机)

    这是BC上的一道题,当时比赛没有做,回头看看题解,说是AC自动机,想着没有写过AC自动机,于是便试着抄抄白书的模板,硬是搞了我数个小时2000ms时限1800过了= = ! 这里就直接贴上BC的结题报 ...

  5. 【hdu 6172】Array Challenge(数列、找规律)

    多校10 1002 HDU 6172 Array Challenge 题意 There's an array that is generated by following rule. \(h_0=2, ...

  6. HDU 4947 GCD Array 容斥原理+树状数组

    GCD Array Time Limit: 11000/5500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  7. HDU - 6197:array array array (简单LIS)

    One day, Kaitou Kiddo had stolen a priceless diamond ring. But detective Conan blocked Kiddo's path ...

  8. HDU 5587:Array

    Array  Accepts: 118  Submissions: 232  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 131072/ ...

  9. HDU 3854 Glorious Array(树状数组)

    题意:给一些结点,每个结点是黑色或白色,并有一个权值.定义两个结点之间的距离为两个结点之间结点的最小权值当两个结点异色时,否则距离为无穷大.给出两种操作,一种是将某个结点改变颜色,另一个操作是询问当前 ...

随机推荐

  1. _DataStructure_C_Impl:图的最小生成树

    #include<stdio.h> #include<stdlib.h> #include<string.h> typedef char VertexType[4] ...

  2. CSS改变字体下划线颜色

    下图是网页中一个非常普通的列表. watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvQXVndXMzMzQ0/font/5a6L5L2T/fontsize/40 ...

  3. Jmeter查看QPS和响应时间随着时间的变化曲线

    以下两个插件提供测试结果,扩展图表显示 --- Response Times Over Time --- Transactions per Second 1.打开 https://jmeter-plu ...

  4. docker笔记一

    docker概念介绍: docker 是一个装在linux上的普通的软件.利用docker的命令,可以创建一个带有linux操作系统的镜像文件,docker命令运行这个带的linux操作系的镜像文件, ...

  5. Channel (Java NIO)

    [正文]netty源码死磕1.3:  Java NIO Channel 1. Java NIO Channel 1.1. Java NIO Channel的特点 和老的OIO相比,通道和NIO流(非阻 ...

  6. What is the difference between iterations and epochs in Convolution neural networks?

    https://stats.stackexchange.com/questions/164876/tradeoff-batch-size-vs-number-of-iterations-to-trai ...

  7. 【题解】Cutting Game

    [题解]Cutting Game vjudge 谈谈对\(sg\)函数的理解? 浅谈公平组合游戏IGC //@winlere #include<cstring> #include<c ...

  8. 我的Android进阶之旅------>如何获取系统中定义了那些权限

    在Window控制台中输入如下命令可以看到Android系统中列出的所有权限(如果自定义权限注册成功,在这里也会找到这些自定义的权限) adb shell pm list permissions C: ...

  9. pip-grep

    Pip-pop pip-grep主要是用于方便查看Requirements.txt中那些模块是安装了的.也就是通过输入的然后模块名称然后在Requirements.txt中进行查询.里面比较难的就是d ...

  10. php类和对象(一)

    对象:任何东西都可以称为对象,类实例化出来的东西类:对所有同类的对象抽象出来的东西 Info: Code,Name,Sex,Nation,Birthday对象:一条具体的信息 p001 张三 男 汉族 ...