HDU 5635--LCP Array —————— "idea question"

Source: Internet
Author: User

LCP Array

Time limit:4000/2000 MS (java/others) Memory limit:131072/131072 K (java/others)
Total submission (s): 830 Accepted Submission (s): 232


Problem Descriptionpeter has a strings =s1s 2 sn , letSuffI= Sis I+1 sn Being the suffix start withI-th character ofs. Peter knows the LCP (longest common prefix) of each of the adjacent suffixes which denotes asAI=Lcp(suffi,suffi+1)(1≤i<n ).

Given the LCP array, Peter wants to know how many strings containing lowercase 中文版 letters only would satisfy the LCP a Rray. The answer may too large, just print it modulo 9+7.

Inputthere is multiple test cases. The first line of input contains an integerTindicating the number of test cases. For each test case:

The first line contains an integerN(2≤n≤5) -The length of the string. The second line containsn−1 Integers:a1,a2,.. . ,an−1 (0≤ai≤n) .

The sum of values of n in all test cases doesn ' t exceed 6.

Outputfor each test case output one integer denoting the answer. The answer must be printed modulo9+7.

Sample Input330 0 43 2 1 31 2

Sample Output16250260

Sourcebestcoder Round #74 (Div.2) Topic: PROBLEM-solving ideas: Because the AI is the longest common prefix of the adjacent suffix LCP, then we handwritten a few samples corresponding to the string to see if there is any law, we found when a[i-1]!=0& &a[i] >= A[i-1] is not possible to exist the corresponding string such as 1 2 0 or 1 1 0, even if the decrement, should be reduced by 1, and A[i] <= n-i, that is suff[i] and suff[i+1] The longest public prefix should be less than n-i, There is a restrictive relationship. There is a 0 of the number is the result should be multiplied by the number of 25, if the given data is a non-0 solution, then the result of the minimum solution should be 26, so initialized to 26.
#include <stdio.h> #include <string.h> #include <iostream> #include <vector> #include < math.h> #include <map> #include <set> #include <queue> #include <stack> #include <string > #include <stdlib.h> #include <algorithm>using namespace std;typedef long long ll;const int maxn = 1e6;    Const LL MOD = 1000000007;int a[maxn];int main () {int cas;    scanf ("%d", &cas);        while (cas--) {int n, flag = 0, c = 0;        scanf ("%d", &n);            for (int i = 1; i < n; i++) {scanf ("%d", &a[i]);            if (!a[i]) C + +;            if (A[i] > N-i) {//restriction flag = 1;            } if (a[i-1]! = 0 && a[i-1]-a[i]! = 1) {//minus 1 decrements flag = 1;        }} if (flag) {puts ("0"); continue;        } LL ans = 26;        for (int i = 1; I <= C; i++) {ans = (ans *)% mod;    } printf ("%lld\n", ans); } return 0;} /*5550 1 0 4501 0 243 2 150 1 2 070 0 3 2 1 0*/ 

  

HDU 5635--LCP Array —————— "idea question"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.