1004 Distinct Sub-palindromes (sign in)
Meaning of the title: the given length is nnstringSS of nS , the task is to outputtheSSwith the least number ofdifferentsub-palindromesThe number of S
Ideas:
At first I thought it was a dp push sequence, combinatorics started...
But when I pushed it by hand, it seemed like a simple sign-in question. First,
find the sequence with the fewest sub-palindromes.
- n = 1 n=1 n=1 : 26 letters
- n = 2 n=2 n=2: 2 6 2 26^2 262( a a aa a a俩:a, aaa, aaa , a ; two twoa b俩:a, ba, ba,b)
- n = 3 n=3 n=3: 2 6 3 26^3 263 (Push it by yourself and found that you can put it anywhere, the number of different sub-palindromes is 3)
- n ≥ 4 : A 3 26 = 26 ∗ 25 ∗ 24 n\ge4:A_{3}^{26}=26*25*24 n≥4:A326=26∗25∗2 4 , Choose any three different letters and arrange them in the specified order (ex: abcabc), the number of different sub-palindromes is 3.
Code:
int main() {
LL t, n;
LL ans = 0;
cin >> t;
while (t--)
{
cin >> n;
if (n <= 3) {
cout << qpow(26, n) << endl;
}
else
{
ans = (26 * 25 * 24) % MOD;
cout << ans << endl;
}
}
return 0;
}