LCP Array

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

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≤105) -- 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 106.
 
Output
For each test case output one integer denoting the answer. The answer must be printed modulo 109+7.
 
Sample Input
3
3
0 0
4
3 2 1
3
1 2
 
Sample Output
16250
26
0

题解:给出最大相邻后缀的最大前缀让找小写字母组成的串的种数

可以找到规律,当出现数组不等于0的时候,必然是递减的;然后找里面0和连续递减串的个数;

就是26*25^m

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<string>
using namespace std;
const int INF=0x3f3f3f3f;
#define SI(x) scanf("%d",&x)
#define PI(x) printf("%d",x)
#define P_ printf(" ")
#define mem(x,y) memset(x,y,sizeof(x))
typedef long long LL;
const int MOD=1e9+;
const int MAXN=1e5+;
int a[MAXN];
LL solve(int N){
int cnt=N;
a[N]=;
for(int i=;i<=N;i++){
if(a[i-]!=&&a[i]!=a[i-]-)return ;
if(a[i-])cnt--;
}
LL ans=;
for(int i=;i<cnt;i++){
ans=ans*%MOD;
}
return ans;
}
int main(){
int T,N;
SI(T);
while(T--){
SI(N);
int cnt;
for(int i=;i<N;i++){
SI(a[i]);
}
printf("%I64d\n",solve(N));
}
return ;
}

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. hdu-5635 LCP Array

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

  4. Beauty of Array(思维)

    Beauty of Array Time Limit: 2 Seconds      Memory Limit: 65536 KB Edward has an array A with N integ ...

  5. Codeforces 950D A Leapfrog in the Array (思维)

    题目链接:A Leapfrog in the Array 题意:给出1-n的n个数,从小到大每隔一个位置放一个数.现在从大到小把数往前移动,每次把最右边的数移动最靠右边的空格处直到n个数都在前n个位置 ...

  6. CF949B A Leapfrog in the Array 思维题,推理

    题意: Dima是一名初级程序员. 在他的工作中,他经常不断地重复以下操作:从数组中删除每个第二个元素. 有一天,他对这个问题的解决方案感到厌倦,他提出了以下华丽的算法. 假设有一长度为2n的数组,最 ...

  7. Codeforces 950D A Leapfrog in the Array ( 思维 && 模拟 )

    题意 : 给出 N 表示有标号 1~N 的 N 个数,然后从下标 1 开始将这 N 个数每隔一位放置一个,直到 N 个数被安排完,现在有一个操作就是每次将数列中最右边的数向离其左边最近的空缺处填上,一 ...

  8. Codeforces Round #643 (Div. 2) D. Game With Array (思维,构造)

    题意:给你两个正整数\(N\)和\(S\),构造一个长度为\(N\)并且所有元素和为\(S\)的正整数数组,问是否能找到一个\(K (0\le K \le S)\)使得这个数组的任意_子数组_的和都不 ...

  9. BestCoder Round #74 (div.2)

    组合 1001 LCP Array 第一题就小难,出题的好像是浙大的大牛? 找到一个规律:a[i] = x, s[i..i+x]都想同.a[i] = a[i+1] + 1 (a[i] > 0), ...

随机推荐

  1. 可获取公网IP的网址

    由于代理检验需要,现在小站经受不住大流量测试,于是多收集了一些. http://1111.ip138.com/ic.asp, http://ip.360.cn/IPShare/info, http:/ ...

  2. Delphi 线程Timer (TThreadTimer)

    delphi 自带的Timer控件,使用方便,但它的 OnTimer 事件是在主线程中引发的. 如果在事件中执行较耗时的代码,会引起主界面假死.故实现一个线程的Timer就有必要了. TThreadT ...

  3. DevC++ 工程没有调试信息的解决办法

    DevC++4.9.9.2中,按 F8 开始调试.提示信息为:工程没有调试信息,您想打开工程的调试选项并重新生成吗?选择是后,再按F8,仍旧是这个信息.什么原因呢? 按照帮助,Frequently A ...

  4. Java基础笔记-String类2

    StringBuffer 特点: 是字符串缓冲区. 是一个容器,其长度可变,可以操作添加多个数据类型. 最后通过toString方法变成字符串. 被final锁修饰,因此不能被继承. 存储: 方法1: ...

  5. js在线题目

    在线题目: https://www.nowcoder.com/ta/js-assessment

  6. sticker.js贴纸效果

    http://stickerjs.cmiscm.com/ <div class="sticker gbtags"></div> <!-- 引用Java ...

  7. UVa 821 Page Hopping

    题意: 给出一个有向图,求所有路径(两点间的最短路径)的平均值. 分析: 用floyd求两点间的最短距离,然后求平均就好. 代码: #include <iostream>#include ...

  8. php安装配置文件 源码和yum版

    源码安装 ./configure --prefix=/usr/local/services/php \--with-config-file-path=/usr/local/service/php/et ...

  9. 《高性能JavaScript》的新征程

    已经学了<JavaScript语言精粹>,现在学高性能. JS的出现是为了改善网页用户体验的,随着互联网通信速度的改善.计算机性能的提升,web越发丰富:但一段时间内,JS的引擎变化不大. ...

  10. _cdel stdcall

    __cdecl 是C Declaration的缩写(declaration,声明),表示C语言默认的函数调用方法:所有参数从右到左依次入栈,这些参数由调用者清除,称为手动清栈.被调用函数不会要求调用者 ...