2020杭電多校第一場 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 and v are distinct if their lengths are different or for
some i (0≤i≤length), u
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
簽到。當n<=3時直接輸出pow(26, n),當n大於3時構造abcabcabc……這樣能保證s內沒有長度大於1的迴文子串,且長度為1的不同的迴文子串只有三個(如果用ababab這樣構造顯然會有aba這樣的子串,不滿足不同的迴文子串最小;如果用四個不同字母來構造又浪費了…)。當然a,b和c可以換成任意三個字母,因此直接輸出C(26, 3) * A(3, 3)即可。
#include <bits/stdc++.h> #define mod 998244353 using namespace std; long long fpow(long long a, long long b) { long long ans = 1 % mod; for(; b; b >>= 1) { if(b & 1) ans = ans * a % mod; a = a * a % mod; } return ans; } int main() { int t; cin >> t; while(t--) { long long n; cin >> n; if(n <= 3) cout << fpow(26, n) << endl; else cout << 26 * 25 * 24 / 6 * 6 << endl; } return 0; }