2020 Multi-University Training Contest 1 补题
朝鲜出题,作为新手感觉难度很大。
目录
1001 Avian Darts
待更新
1002 Boring Task
待更新
1003 Cookies
待更新
1004 Distinct Sub-palindromes
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 u u and v v v are distinct if their lengths are different or for some i i i (0≤ i i i≤length), u i _i i≠v i _i i. For example, string “aaaa” contains only 4 distinct sub-palindromes which are “a”, “aa”, “aaa” and “aaaa”.
翻译
S是一串长度为 n 的字符串。这串字符串仅包括小写英文字母
你的任务就是数出在n长度的不同的字符串中,有着最小不同连续的回文子串数目的字符串有多少个。
就比如 n 为 4 那么字符串可以是 aaaa,他的不同回文子串一共有4种,分别是 a,aa,aaa,aaaa
不同的前缀长度不同或者字符串不相等(即 strcmp( u u u, v v v) != 0,其中 u u u, v v v为回文)
Input
The first line contains an integer T T T ( 1 ≤ T ≤ 1 0 5 ) (1≤T≤10^5) (1≤T≤105), denoting the number of test cases.
The only line of each test case contains an integer n ( 1 ≤ n ≤ 1 0 9 ) n (1≤n≤10^9) 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
当n=1时,26种,显而易见
当n=2时,第一位有26种取法,第二位有26种取法(例子 aa:a/aa,ac:a/c)
当n=3时,第一位26,第二位26,第三位26(可重复,aaa,aba,abc 都有3种)
当n=4时,第一位26,第二位26,第三位26,第四位呢?
比如
abca 有 a b c 然后没了。所以这个是最少,这后面都是重复的。并且按照abc的顺序
比如六个
abcabc
和abccba
肯定是abcabc最少
当
n
>
=
4
n>=4
n>=4时,数量为
26
∗
25
∗
24
26*25*24
26∗25∗24
当
n
<
=
3
n<=3
n<=3时,数量为
2
6
n
26^n
26n
代码
#include <iostream>
using namespace std;
long long ppow(long long x,long long y){
for(long long i=1;i<y;i++){
x*=26;
}
return x;
}
int main(void){
long long t,n;
cin >> t;
while(t--){
scanf("%d", &n);
if(n<=3) printf("%lld\n",ppow(26,n));
else printf("%lld\n",26*25*24);
}
return 0;
}