题目链接: 04-Distinct Sub-palindromes
Description
题意:给定n,求长度为n的字符串中包含的不同次回文串的数目的最大值
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 ≤ 105), denoting the number of test cases.
The only line of each test case contains an integer n (1 ≤ n ≤ 109).
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
Method
- n == 1 时, 显然 不同次回文子串数 最大值为 26;
- n == 2 时,aa, ab 均包含两个 次回文子串,最大值为 262;
- n == 3 时,有 aaa, aab, aba, abc 这四种次回文串,且均为 3 个, 最大值为 263;
- n >= 4 时,考虑在 n == 3 的情况上加上一个字符,只需考虑abcd这种情况,回文子串数最少为3,所以最大值 为 26×25×24;
Code
详见注释
#include <iostream>
#include <cstdio>
using namespace std;
#define Max 1e5+5
#define ll long long
#define mod 998244353
template<typename T> T get(T a, T b) { //快速幂(可以不用快速幂,连乘即可)
ll s = 1%mod;
while (b) {
if (b%2 == 1) {
s = (s*a)%mod;
}
b /= 2;
a = (a%mod)*(a%mod)%mod;
}
return s;
}
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
ll sum, n, k=26;
scanf("%lld", &n);
if(n <= 3) sum = get(k, n)%mod; //如果n <= 3, 次回文串的个数为 26^n
else sum = 26*25*24%mod; //如果n > 3,次回文串的个数为 26*25*24
printf("%lld\n", sum);
}
return 0;
}
蒟蒻一只,欢迎指正