2020杭电多校1

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取模。
分析

  1. 当n=1时,对于26个任意一个字母构成的字符串,子串都是回文串,回文串的数量为1
  2. 当n=2时,构成的字符串有“aa”和“ab”两种情况(排列组合)。这两种字符串子串为回文串的数量都为2.
  3. 当n=3时,构成的字符串有“aaa”和“abc”和“aba”三种情况。这三种字符串子串为回文串的数量都为3.
  4. 当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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zaiyang遇见

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值