Distinct Sub-palindromes
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 450 Accepted Submission(s): 304
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≤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
Your task is to count the number of different S with the minimum number of distinct sub-palindromes. S
这道题!!英语好很重要!!!!读错题意人都傻了
题意:问长度为n的字符串中,不同的回文子串个数最少的串有多少种,答案对1e9+7取模
解题思路:思维题,先考虑n很大的时候,如果是如abcabc…这样排列,不同的回文子串个数就是3,只有这一种情况是回文子串最少的。当n>=4的时候不同回文子串个数不可能小于3个,而如果是3个就最多有3个字母. 当是3个字母的时候,肯定不可以有相邻的相同字母,也不能有一个位置左右两边是同一个字母,那么就只能是abcabc……这种形式了。所以n>=4的时候答案是26 * 25 * 24,而n <= 3的时候手画一下会发现答案是26n
Code
#include<cmath>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<map>
typedef long long ll;
using namespace std;
const double pi=4*atan(1.0);
const ll mod=1e9+7;
const int inf=0x3f3f3f3f;
using namespace std;
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
if(n==1)printf("26\n");
else if(n==2)printf("%d\n",26*26);
else if(n==3)printf("%d\n",26*26*26);
else printf("%d\n",26*25*24);
}
return 0;
}