HDU 5635
2016-03-05 22:37
162 查看
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5635
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 284 Accepted Submission(s): 79
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
题意:有一个长度为n的字符串,给出长度为n-1的数列
第n个数代表以第n个字母为开头的字符串后缀和第n+1个字母为开头的字符串后缀的相同前缀值
字符串由26个小写字母组成,求给出数列后符合条件的字符串有几个
对于给的an,如果不是0,那接下来必定是an-1,an-2,一直排列到0,如果不是这样就不符合输出0
另外最后一个数只能是1或者是0,不符合的话同样输出0
如果两个条件都符合,记录下0的数量(包含最后一个数为1的可能)
最后26*25^n-1即为答案
妈的智障...div2的第一题就不会
关系很好推出来...就是手贱写了一个快速幂还是错的...
还是错的...还是错的...还是错的...
生无可恋系列
下面代码
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<functional>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
__int64 k=1e+9+7;
int a[100005];
int main()
{
int i,n,nn;
__int64 sum,ans;
scanf("%d",&nn);
while(nn--)
{
memset(a,0,sizeof(a));
scanf("%d",&n);
for(i=1;i<n;i++)
scanf("%d",&a[i]);
i=1;
sum=0;
while(i<=n)
{
if(a[i]==0)
{
if(a[i-1]==0) sum++;
else if(a[i-1]!=1) {sum=0; break;}
}
else if(a[i]!=0)
{
if(a[i-1]==0) sum++;
else if(a[i-1]!=a[i]+1) {sum=0; break;}
}
i++;
}
ans=0;
if(sum!=0)
{
ans=1;
for(i=1;i<sum;i++)
ans=(ans*25)%k;
ans=(ans*26)%k;
}
printf("%I64d\n",ans);
}
return 0;
}
LCP Array
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 284 Accepted Submission(s): 79
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
题意:有一个长度为n的字符串,给出长度为n-1的数列
第n个数代表以第n个字母为开头的字符串后缀和第n+1个字母为开头的字符串后缀的相同前缀值
字符串由26个小写字母组成,求给出数列后符合条件的字符串有几个
对于给的an,如果不是0,那接下来必定是an-1,an-2,一直排列到0,如果不是这样就不符合输出0
另外最后一个数只能是1或者是0,不符合的话同样输出0
如果两个条件都符合,记录下0的数量(包含最后一个数为1的可能)
最后26*25^n-1即为答案
妈的智障...div2的第一题就不会
关系很好推出来...就是手贱写了一个快速幂还是错的...
还是错的...还是错的...还是错的...
生无可恋系列
下面代码
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<functional>
#include<queue>
#include<vector>
#include<set>
#include<map>
using namespace std;
__int64 k=1e+9+7;
int a[100005];
int main()
{
int i,n,nn;
__int64 sum,ans;
scanf("%d",&nn);
while(nn--)
{
memset(a,0,sizeof(a));
scanf("%d",&n);
for(i=1;i<n;i++)
scanf("%d",&a[i]);
i=1;
sum=0;
while(i<=n)
{
if(a[i]==0)
{
if(a[i-1]==0) sum++;
else if(a[i-1]!=1) {sum=0; break;}
}
else if(a[i]!=0)
{
if(a[i-1]==0) sum++;
else if(a[i-1]!=a[i]+1) {sum=0; break;}
}
i++;
}
ans=0;
if(sum!=0)
{
ans=1;
for(i=1;i<sum;i++)
ans=(ans*25)%k;
ans=(ans*26)%k;
}
printf("%I64d\n",ans);
}
return 0;
}
相关文章推荐
- 12.1 字段数据类型(Field datatypes)
- Android实现随触摸移动而变化的效果
- Activity的生命周期全面分析
- HDU 5638 Toposort 拓扑排序 优先队列
- 334. Increasing Triplet Subsequence
- LeetCode94——Binary Tree Inorder Traversal
- 打印1到最大的n位数 Java
- Vulkan API基本概念
- Vulkan API基本概念
- Fragmetn有关
- Vulkan API基本概念(一)
- HTML5开发入门经典教程和案例合集(含视频教程)
- iOS边练边学--plist文件,懒加载,模型初使用--补充instancetype
- Quartz定时任务,Quartz Spring定时任务,spring多个定时任务Quartz配置,示例,详解
- PAT程序能力考题——甲级1010(比较任意进制转换的两个数字,是否相等)
- 制作启动U盘
- C/C++ 内存分配方式,堆区,栈区,new/delete/malloc/free
- 文章标题
- #if和if的区别以及#pragma、unused
- 天灵灵,地灵灵,但愿这个一定灵!!!python调用win32api,启动应用程序窗口