LCP Array(思维)
LCP Array
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 90 Accepted Submission(s): 26
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.
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.
3
0 0
4
3 2 1
3
1 2
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(思维)的更多相关文章
- hdu 5635 LCP Array(BC第一题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5635 LCP Array Time Limit: 4000/2000 MS (Java/Others) ...
- HDU 5635 ——LCP Array ——————【想法题】
LCP Array Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
- hdu-5635 LCP Array
LCP Array Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
- Beauty of Array(思维)
Beauty of Array Time Limit: 2 Seconds Memory Limit: 65536 KB Edward has an array A with N integ ...
- Codeforces 950D A Leapfrog in the Array (思维)
题目链接:A Leapfrog in the Array 题意:给出1-n的n个数,从小到大每隔一个位置放一个数.现在从大到小把数往前移动,每次把最右边的数移动最靠右边的空格处直到n个数都在前n个位置 ...
- CF949B A Leapfrog in the Array 思维题,推理
题意: Dima是一名初级程序员. 在他的工作中,他经常不断地重复以下操作:从数组中删除每个第二个元素. 有一天,他对这个问题的解决方案感到厌倦,他提出了以下华丽的算法. 假设有一长度为2n的数组,最 ...
- Codeforces 950D A Leapfrog in the Array ( 思维 && 模拟 )
题意 : 给出 N 表示有标号 1~N 的 N 个数,然后从下标 1 开始将这 N 个数每隔一位放置一个,直到 N 个数被安排完,现在有一个操作就是每次将数列中最右边的数向离其左边最近的空缺处填上,一 ...
- Codeforces Round #643 (Div. 2) D. Game With Array (思维,构造)
题意:给你两个正整数\(N\)和\(S\),构造一个长度为\(N\)并且所有元素和为\(S\)的正整数数组,问是否能找到一个\(K (0\le K \le S)\)使得这个数组的任意_子数组_的和都不 ...
- BestCoder Round #74 (div.2)
组合 1001 LCP Array 第一题就小难,出题的好像是浙大的大牛? 找到一个规律:a[i] = x, s[i..i+x]都想同.a[i] = a[i+1] + 1 (a[i] > 0), ...
随机推荐
- Java Script 中 ==(Equal) 和 === (Identity Equal) 的区别和比较算法逻辑
判断两个变量是否相等在任何编程语言中都是非常重要的功能. JavaScript 提供了 == 和 === 两种判断两个变量是否相等的运算符,但我们开始学习的时候 JavaScript 的时候,就被一遍 ...
- javascript事件设计模式
JavaScript事件设计模式 http://plkong.iteye.com/blog/213543 http://www.docin.com/p-696665922.html
- (九)boost库之文件处理filesystem
(九)boost库之文件处理filesystem filesystem库是一个可移植的文件系统操作库,它在底层做了大量的工作,使用POSIX标准表示文件系统的路径,使C++具有了类似脚本语言的功能 ...
- C语言的本质(15)——C语言的函数接口入门
C语言的本质(15)--C语言的函数接口 函数的调用者和其实现者之间存在一个协议,在调用函数之前,调用者要为实现者提供某些条件,在函数返回时,实现者完成调用者需要的功能. 函数接口通过函数名,参数和返 ...
- read write spinlock
发一个自己基于 C++11 写的 read write spinlock,在 MinGW 4.8.2 (gcc 4.8 全面支持c++ 11,但由于gcc windows平台 libstdc++ 目前 ...
- poj 1083 Moving Tables_dp
题意:给你n个凳子,接着告诉你一个凳子从a房间到b房间,运输时间为10分钟,走廊很窄能通过一张凳子,当然不堵塞的话能同时扮凳子,问最小花费多少时间 因为数据很小就直接用数组统计了,a,b如果是奇数的话 ...
- Working with Strings(使用Oracle字符串)
Working with Strings By Steven Feuerstein Part 3 in a series of articles on understanding and using ...
- JavaScript中模块“写法”
在JavaScript模块到底是什么 event = function() { // do more return { bind: function() {}, unbind: function() ...
- C#中按指定质量保存图片的实例代码 24位深度
/// <summary> /// 按指定的压缩质量及格式保存图片(微软的Image.Save方法保存到图片压缩质量为75) /// </summary ...
- document load 与document ready的区别
页面加载完成有两种事件 1.load是当页面所有资源全部加载完成后(包括DOM文档树,css文件,js文件,图片资源等),执行一个函数 问题:如果图片资源较多,加载时间较长,onload后等待执行的函 ...