zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    vue中Axios的封装和API接口的管理
    解决Vue报错:TypeError: Cannot read property 'scrollHeight' of undefined
    JS-scrollTop、scrollHeight、clientTop、clientHeight、offsetTop、offsetHeight的理解
    理解Vue中的ref和$refs
    理解Vue中的nextTick
    CSS——overflow的参数以及使用
    JS数据结构——队列
    Vue中实现聊天窗口overflow:auto自动滚动到底部,实现显示当前最新聊天消息
    Vue中无法检测到数组的变动
    JS-观察者模式
  • 原文地址:https://www.cnblogs.com/handsomecui/p/5246030.html
Copyright © 2011-2022 走看看