2020杭电HDU-6754多校第一场Distinct Sub-palindromes(思维+读题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6754

Problem Description

S is a string of length n. S consists of lowercase English alphabets.

Your task is to count the number of different S with the minimum number of distinct sub-palindromes. Sub-palindrome is a palindromic substring.

Two sub-palindromes u and v are distinct if their lengths are different or for some i (0≤i≤length), ui≠vi. For example, string “aaaa” contains only 4 distinct sub-palindromes which are “a”, “aa”, “aaa” and “aaaa”.

Input
The first line contains an integer T (1≤T≤10^5), denoting the number of test cases.

The only line of each test case contains an integer n (1≤n≤10^9).

Output
For each test case, output a single line containing the number of different strings with minimum number of distinct sub-palindromes.

Since the answer can be huge, output it modulo 998244353.

Sample Input
2

1 2

Sample Output
26

676

emmm,题目看的很迷。。。不知道他在说些什么鬼。。。可能是我的英语+语文双重的不好吧QAQ。
题目的大意是,你要构造一个长度为n的字符串,使得字符串的子串为回文串的数量最少。
那么我们先考虑一下n=1的情况吧。这个似乎没什么好说的,总共26种情况,每种情况的回文子串数量都是1

当n=2的时候,有ab,aa两种情况第一种也有两个回文子串为:“a”,“b”,第二种也只有两个:“a”,“aa”。所以他们都是OK的,也就是26*26种情况了

当n=3的时候,有如aaa,abb,aba,abc四种情况,他们的回文子串也都是1。

当n=4的时候我们考虑在n=3的基础上添加一个字母,如果是在类型1里面加的话,那么必然会增加一个回文子串,在第二种类型中添加也会增加一个回文,第三种也是一样的,只有第四中,如果我们在后面添加一个'a'的话,那么它的回文子串是不增加的。那么于是又回到了n=1的时候了。

所以当n<=3的时候,答案是$26^n$,当n>3的时候,答案就是$26*25*24$了

以下是AC代码:

#include <bits/stdc++.h>
using namespace std;

int qpow(int a,int b)
{
    int ans=1;
    while (b){
        if (b&1) ans=ans*a;
        a*=a;
        b>>=1;
    }
    return ans;
}

int main(int argc, char const *argv[])
{
    int t;
    scanf ("%d",&t);
    while (t--){
        int n;
        scanf ("%d",&n);
        if (n<=3) printf("%d\n",qpow(26,n));
        else printf("%d\n",26*25*24);
    }
    return 0;
}

 

posted @ 2020-07-21 21:53  lonely_wind  阅读(447)  评论(0编辑  收藏  举报