BestCoder Round #74 (div.2)【1排列组合】
来源:互联网 发布:崇洋媚外的中国知乎 编辑:程序博客网 时间:2024/05/16 01:01
题目链接:点击打开链接
LCP Array
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 1527 Accepted Submission(s): 465
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 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 integer T 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 modulo 109+7 .
Sample Input
330 043 2 131 2
Sample Output
16250260
大意:
问题描述
Peter有一个字符串s=s1s2...sn, 令suffi=sisi+1...sn是s第i字符开头的后缀. Peter知道任意两个相邻的后缀的最长公共前缀ai=lcp(suffi,suffi+1)(1≤i<n).现在给你数组a, Peter有多少个仅包含小写字母的字符串满足这个数组. 答案也许会很大, 你只要输出对109+7取模的结果即可.
输入描述
输入包含多组数据. 第一行有一个整数T, 表示测试数据的组数. 对于每组数据:第一行包含一个整数n (2≤n≤105)表示字符串的长度. 第二行包含n−1个整数: a1,a2,...,an−1 (0≤ai≤n).所有数据中n的和不超过106.
输出描述
对于每组数据, 输出答案对109+7取模的结果.
思路:观察 a[i] 可以发现,a[i] 是逐一递减的而且每次递减值为 1,直至递减为 0,再开始又一次的递减。
发现是排列组合问题等价于排列 26 种颜色,两两相邻不相同放同一种颜色,第一次肯定是放 26 种颜色啦,然后碰见一次 0 放一种颜色
#include<cstdio>#include<cstring>#include<algorithm>#define LL long longusing namespace std;const LL mod=1e9+7;int n;int a[100010];int main(){int t;scanf("%d",&t);while(t--){scanf("%d",&n);bool flag=1;LL ans=26;for(int i=1;i<n;i++){scanf("%d",a+i);if(a[i]>=n-i+1)flag=0;if(a[i-1]!=0&&a[i]!=a[i-1]-1){flag=0;}if(a[i]==0)ans=ans*25%mod;}if(flag)printf("%lld\n",ans);elseputs("0");}return 0;}
0 0
- BestCoder Round #74 (div.2)【1排列组合】
- BestCoder Round #74 (div.2)
- hdu 5637 BestCoder Round #74 (div.2)
- hdu5635 BestCoder Round #74 (div.2)
- BestCoder Round #74 (div.2) LCP Array
- BestCoder Round #11 (Div. 2)
- BestCoder Round #11 (Div. 2)
- BestCoder Round #50 (div.2)
- BestCoder Round #50 (div.2)
- BestCoder Round 50 (div 2)
- BestCoder Round #50 (div.2)
- #BestCoder Round #50 (div.2)
- BestCoder Round #50 (div.2)
- BestCoder Round #54 (div.2)
- BestCoder Round #56 (div.2)
- BestCoder Round #58 (div.2)
- BestCoder Round #59 (div.2)
- BestCoder Round #59 (div.2)
- C#调用PB写的com组件dll
- 构造器
- Struts2学习(二)---一个struts2的登陆例子
- JAVA求学之路第一天
- 递归大总结之指数运算
- BestCoder Round #74 (div.2)【1排列组合】
- java编程题:以三种不同方式输出九九乘法表(java)
- part5-2 基础DOM和CSS操作
- Java 之集合排序
- linux(ubuntu)安装PHP7以及memcache、redis等扩展
- [MMDxUE4]将MMD的模型和动作、相机文件导入UE4中使用
- usb 中传输类型
- MVP架构的简单实现
- 周期串(Periodic Strings,UVa455)