hdu 5635 LCP Array【思维】
来源:互联网 发布:java log输出 到网页 编辑:程序博客网 时间:2024/05/29 03:20
LCP Array
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 596 Accepted Submission(s): 161
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 asai=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 modulo109+7 .
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
Input
There are multiple test cases. The first line of input contains an integerT indicating the number of test cases. For each test case:
The first line contains an integern (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 ofn in all test cases doesn't exceed 106 .
The first line contains an integer
The sum of values of
Output
For each test case output one integer denoting the answer. The answer must be printed modulo109+7 .
Sample Input
330 043 2 131 2
Sample Output
16250260
Source
BestCoder Round #74 (div.2)
真特喵的是一个很蛋疼的题目、其实如果题读懂了,结果也就很容易弄出来了、我们这边有三个人同时做这个题,最终因为每一个人的意见不同,导致结果不统一,更导致推论的不统一,更导致了没法实践、、、、、、一直都在Wa,终测之后的正确率也很容易证明,这是一个坑B的题目。。。
其实题干的意识是保证了最长前缀是一定从第一个字符开始匹配上的。我们一直在想的问题是强调了最长前缀应该是表示最长的部分,不用一定从第一个字符开始匹配,那么如果按照题目保证的来,那么a【】一定是递减的,而且递减一定是相差1的、如果不是相差1,那么是不可能的、除非当前a【】是0、
AC代码:
#include<stdio.h>#include<string.h>using namespace std;#define ll long long intconst int mod = 1e9 + 7;ll a[121212];int main(){ int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); for(int i=0;i<n-1;i++) { scanf("%I64d",&a[i]); } ll output=26;ll cur=0; for(int i=n-2;i>=0;i--) { if(a[i]-cur==1) { cur=a[i]; } else if(a[i]==0) { output=(output*25)%mod; cur=0; } else { output=0; break; } } printf("%I64d\n",output); }}
0 0
- hdu 5635 LCP Array【思维】
- HDU problem 5635 LCP Array【思维】
- hdu 5635 LCP Array
- HDU 5635 LCP array
- HDU 5635:LCP Array
- HDU 5635 LCP Array
- 【HDU 5635 LCP Array】
- HDU 5635 LCP Array(水~)
- hdu 4898 LCP+贪心思维
- hdu 5635 LCP Array(BC第一题)
- 【hdu 5635】LCP Array 中文题意&题解&代码(C++)
- hdu 5635 LCP Array(BC第一题)
- ♥HDOJ 5635-LCP Array
- hdoj 5635 LCP Array 【模拟】
- hdoj 5635 LCP Array (模拟)
- LCP Array
- hdoj LCP Array 5635 (找规律)
- HDU5635 LCP Array BestCoder
- Thinkphp调用ajaxReturn中文乱码解决办法
- codeforces 55D. Beautiful numbers (数位dp)
- Spark 1.6.0 单机安装配置
- codeforces 631E Product Sum (dp凸单调性)
- 在公司编程的大方向上的感悟
- hdu 5635 LCP Array【思维】
- Log4J配置
- 何以诚快变成神经哥了
- 郭霖博客处转载的超赞的Volley用法
- android studio上Svn环境之新手搭建,错误解决。
- 一个没有{}的for循环
- linux系统下的文本处理,awk,sed
- Maya粒子-水滴表面流动效果
- HDOJ——2001 ASCII码排序(java 版)