杭电多校第一场 Distinct Sub-palindromes(思维,构造)

题目传送
题意:
使用26个小写的英文字母,构造长度为n的字符串s。字符串s的 本质不同的回文子串的个数最少,求字符串s种类的数量。

思路:
这是个纯思维构造问题,分情况:
情况1:
当n <= 3时,我们直接这样构造: a,aa,aaa,这种,这样的回文子串一定最少

当n > 3时,我们这样构造,一直abcabcabc…这样的回文子串数量一定是3.

AC代码

#include <bits/stdc++.h>
inline long long read(){char c = getchar();long long x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
const int N = 4e3 + 5;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-7;
const int mod = 1e9+7;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
signed main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    //    freopen("input.txt","r",stdin);
    //    freopen("output.txt","w",stdout);
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        n <= 3 ? cout << (ll)pow(n,n) << endl : cout << 26*25*24 << endl;
    }
}

猜你喜欢

转载自blog.csdn.net/moasad/article/details/107548485
今日推荐