HDU 6754 Distinct Sub-palindromes(2020杭电多校训练第一场)

Distinct Sub-palindromes
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 450 Accepted Submission(s): 304

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≤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
 

Your task is to count the number of different S with the minimum number of distinct sub-palindromes. S

这道题!!英语好很重要!!!!读错题意人都傻了
题意:问长度为n的字符串中,不同的回文子串个数最少的串有多少种,答案对1e9+7取模

解题思路:思维题,先考虑n很大的时候,如果是如abcabc…这样排列,不同的回文子串个数就是3,只有这一种情况是回文子串最少的。当n>=4的时候不同回文子串个数不可能小于3个,而如果是3个就最多有3个字母. 当是3个字母的时候,肯定不可以有相邻的相同字母,也不能有一个位置左右两边是同一个字母,那么就只能是abcabc……这种形式了。所以n>=4的时候答案是26 * 25 * 24,而n <= 3的时候手画一下会发现答案是26n
Code

#include<cmath>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<map>
typedef long long ll;
using namespace std;
const double pi=4*atan(1.0);
const ll mod=1e9+7;
const int inf=0x3f3f3f3f;
using namespace std;

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        if(n==1)printf("26\n");
        else if(n==2)printf("%d\n",26*26);
        else if(n==3)printf("%d\n",26*26*26);
        else printf("%d\n",26*25*24);
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值