♥HDOJ 5635-LCP Array
来源:互联网 发布:wpf 管理系统源码购 编辑:程序博客网 时间:2024/06/05 21:08
LCP Array
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 159 Accepted Submission(s): 47
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)
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int a[1000000];int n;void f(){int i,j;long long ans=26;for(i=1;i<n;i++){if((a[i]-1)!=a[i+1]&&a[i]!=0){printf("0\n");return ;}}int uu=0;for(i=1;i<=n;i++){if(a[i]==0){if(uu>0){ans*=25;ans=ans%1000000007;}elseuu++;}}printf("%I64d\n",ans);}int main(){int t;scanf("%d",&t);while(t--){scanf("%d",&n);int i,j;for(i=1;i<n;i++){scanf("%d",&a[i]);}a[n]=0;f();}return 0;}
1 0
- ♥HDOJ 5635-LCP Array
- hdoj 5635 LCP Array 【模拟】
- hdoj 5635 LCP Array (模拟)
- hdoj LCP Array 5635 (找规律)
- hdu 5635 LCP Array
- HDU 5635 LCP array
- HDU 5635:LCP Array
- HDU 5635 LCP Array
- 【HDU 5635 LCP Array】
- hdu 5635 LCP Array【思维】
- LCP Array
- HDU 5635 LCP Array(水~)
- HDU problem 5635 LCP Array【思维】
- HDU5635 LCP Array BestCoder
- hdu 5635 LCP Array(BC第一题)
- 【hdu 5635】LCP Array 中文题意&题解&代码(C++)
- hdu 5635 LCP Array(BC第一题)
- BestCoder Round #74 (div.2) LCP Array
- 利用泛型实现一个简单的android orm小例子
- 数学排列好难--- QAQ的问题
- LeetCode : Longest Common Prefix [java]
- QVariant类
- UVA1013201串配对
- ♥HDOJ 5635-LCP Array
- 微信iOS卡顿监控系统
- poj Risk 1603 (最短路) 坑
- 关于linux异步通知signal 和QT的信号槽
- 【HPU】[1728]序列找数
- 大型网站架构系列:电商网站架构案例
- vim 多窗口编辑
- GET和POST的区别
- angularjs前端框架