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)(1i<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.
 

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 integer n (2n105) -- the length of the string. The second line contains n1 integers: a1,a2,...,an1(0ain).

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 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