2020 HDU多校 第一场 04-Distinct Sub-palindromes(思维)
题目链接: 04-Distinct Sub-palindromes
Description
题意:给定n,求长度为n的字符串中包含的不同次回文串的数目的最大值
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
Method
- n == 1 时, 显然 不同次回文子串数 最大值为 26;
- n == 2 时,aa, ab 均包含两个 次回文子串,最大值为 262;
- n == 3 时,有 aaa, aab, aba, abc 这四种次回文串,且均为 3 个, 最大值为 263;
- n >= 4 时,考虑在 n == 3 的情况上加上一个字符,只需考虑abcd这种情况,回文子串数最少为3,所以最大值 为 26×25×24;
Code
详见注释
#include <iostream>
#include <cstdio>using namespace std;
#define Max 1e5+5
#define ll long long
#define mod 998244353
template<typename T> T get(T a, T b) { //快速幂(可以不用快速幂,连乘即可)ll s = 1%mod;while (b) {if (b%2 == 1) {s = (s*a)%mod;}b /= 2;a = (a%mod)*(a%mod)%mod;}return s;
}
int main()
{int t;scanf("%d", &t);while(t--){ll sum, n, k=26;scanf("%lld", &n);if(n <= 3) sum = get(k, n)%mod; //如果n <= 3, 次回文串的个数为 26^n else sum = 26*25*24%mod; //如果n > 3,次回文串的个数为 26*25*24 printf("%lld\n", sum);}return 0;
}
蒟蒻一只,欢迎指正
2020 HDU多校 第一场 04-Distinct Sub-palindromes(思维)相关推荐
- 2020 牛客多校第一场
2020 牛客多校第一场 A. B-Suffix Array 后缀数组的思想:倍增+桶排序的方式找出一串连续序列后缀的大小.虽说正常使用的时候都是字典序,但是只要修改排序方式,也能够达到一个类似的&q ...
- python字符串去重及排序 牛客_2018牛客多校第一场 D.Two Graphs
题意: n个点,m1条边的图E1,n个点,m2条边的图E2.求图E2有多少子图跟图E1同构. 题解: 用STL的全排列函数next_permutation()枚举映射.对于每一种映射枚举每一条边判断合 ...
- 2019牛客多校第一场
2019牛客多校第一场 题号 题目 知识点 A Monotonic Matrix B Symmetric Matrix C Fluorescent 2 D Two Graphs E Removal F ...
- 2019年杭电多校第一场 1001题blank(DP)HDU6578
2019年杭电多校第一场 1001题blank(DP)HDU6578 解决思路,开一个DP数组来存储0 1 2 3四个字符最后出现的位置,并且在DP中已经==排好序==. DP开四维,DP[i][j] ...
- 2019HDU多校第一场1001 BLANK (DP)(HDU6578)
2019HDU多校第一场1001 BLANK (DP) 题意:构造一个长度为n(n<=10)的序列,其中的值域为{0,1,2,3}存在m个限制条件,表示为 l r x意义为[L,R]区间里最多能 ...
- 【多校训练】2021牛客多校第一场
[前言] 组队训练的第一场比赛,感觉这场出题十分阴间,后面几个乱搞题根本不会.jpg 赛时只过了5题,rk123,学校参加5/8. A. Alice and Bob [题意] 两人博弈,每次一个人从一 ...
- 【2019多校第一场补题 / HDU6578】2019多校第一场A题1001Blank——dp
HDU6578链接 题意 有一串字符串,仅由 {0,1,2,3}\{0, 1, 2, 3\}{0,1,2,3} 组成,长度为 nnn,同时满足 mmm 个条件.每个条件由三个整数组成:l.r.xl.r ...
- [2019HDU多校第一场][HDU 6578][A. Blank]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6578 题目大意:长度为\(n\)的数组要求分别填入\(\{0,1,2,3\}\)四个数中的任意一个,有 ...
- [2019HDU多校第一场][HDU 6590][M. Code]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6590 题目大意(来自队友):二维平面上有\(n\)个点,每个点要么是黑色要么是白色,问能否找到一条直线 ...
最新文章
- 2022-2028年中国纺织服装专业市场深度调研及前景预测报告(全卷)
- docker 命令详解
- mysql show作用_mysql的show操作
- [原创]位运算符实现两个整数加法运算
- [导入]关于阶乘的两个常见算法及一个相关面试题
- Myeclipse7.X和8.X汉化
- 吴恩达 Drive.ai 因经营困难“卖身”苹果
- pycharm python3.7环境_Python3+Pycharm+PyQt5环境搭建步骤图文详解
- 【软考】2020年下半年计算机技术与软件资格考试划水贴
- MongoDB驱动程序快速入门
- unity urp raytrace体积光god ray效果
- 配置jdk与maven环境变量
- 第八章 云计算原理与技术
- Ant Design + React 中将分页组件的英文转为中文
- PTA 乙级 1003 我要通过! (20 分) C++
- c语言小游戏 贪吃蛇
- 【磨刀不误砍柴工】(SCH-1217) Could not open “XXschematic“ for edit. Would you like to open it for read?问题。
- 鲁大师2023年Q1手机报告:ColorOS蝉联榜首
- 解决:java.lang.IllegalStateExceptio:Underflow in restore - more restores than saves异常,Module闪退
- 一只仓鼠引发的热议HUAWEI nova 青春版超大内存走红