传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5635
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 .
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 .
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;
}