• LCP Array(思维)


    LCP Array

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 90    Accepted Submission(s): 26

    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)(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 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 (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 modulo 109+7.
     
    Sample Input
    3 3 0 0 4 3 2 1 3 1 2
     
    Sample Output
    16250 26 0

    题解:给出最大相邻后缀的最大前缀让找小写字母组成的串的种数

    可以找到规律,当出现数组不等于0的时候,必然是递减的;然后找里面0和连续递减串的个数;

    就是26*25^m

    代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    #include<map>
    #include<string>
    using namespace std;
    const int INF=0x3f3f3f3f;
    #define SI(x) scanf("%d",&x)
    #define PI(x) printf("%d",x)
    #define P_ printf(" ")
    #define mem(x,y) memset(x,y,sizeof(x))
    typedef long long LL;
    const int MOD=1e9+7;
    const int MAXN=1e5+100;
    int a[MAXN];
    LL solve(int N){
        int cnt=N;
        a[N]=0;
        for(int i=2;i<=N;i++){
            if(a[i-1]!=0&&a[i]!=a[i-1]-1)return 0;
            if(a[i-1])cnt--;
        }
        LL ans=26;
        for(int i=1;i<cnt;i++){
            ans=ans*25%MOD;
        }
        return ans;
    }
    int main(){
        int T,N;
        SI(T);
        while(T--){
            SI(N);
            int cnt;
            for(int i=1;i<N;i++){
                SI(a[i]);
            }
            printf("%I64d
    ",solve(N));
        }
        return 0;
    }
  • 相关阅读:
    DELPHI开发LINUX包
    DELPHI开发LINUX的动态库
    中间件测试工具
    CENTOS7安装OPENSSL
    咏南跨平台中间件简介
    IdHTTPServer开发https服务器
    ServiceStack.Redis常用操作
    ServiceStack.Redis 之 IRedisTypedClient<第四篇>
    Redis常用命令速查 <第二篇>
    ServiceStack.Redis之IRedisClient<第三篇>
  • 原文地址:https://www.cnblogs.com/handsomecui/p/5246030.html
Copyright © 2020-2023  润新知