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≤
1
0
5
10^5
105), denoting the number of test cases.
The only line of each test case contains an integer n (1≤n≤ 1 0 9 10^9 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
翻译: 构造一个长度为n的字符串,使得字符串的子串为回文串的数量最少,求这样的字符串的数量。结果对 998244353取模。
分析:
- 当n=1时,对于26个任意一个字母构成的字符串,子串都是回文串,回文串的数量为1
- 当n=2时,构成的字符串有“aa”和“ab”两种情况(排列组合)。这两种字符串子串为回文串的数量都为2.
- 当n=3时,构成的字符串有“aaa”和“abc”和“aba”三种情况。这三种字符串子串为回文串的数量都为3.
- 当n>3时,要使子串为回文串的数量最少,构成“abcabcabcabc···”的形势能保证回文串的数量最少,为3
完整代码:
#include<cstdio>
#include<cstring>
#include<math.h>
#include<iostream>
#include<stdlib.h>
#include<algorithm>
using namespace std;
int quick_mi(int a,int b)
{
int sum=1;
while(b)
{
if(b&1)
sum*=a;
a=a*a;
b>>=1;
}
return sum;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,res;
scanf("%d",&n);
if(n<=3)
res=quick_mi(26,n);
else
res=26*25*24;
cout<<res<<endl;
}
return 0;
}