• 【2020杭电多校】Distinct Sub-palindromes 找规律


    题目链接:Distinct Sub-palindromes

    题意:

    给你一个长度n,你需要找出来一些串,这些串由A...Z和a...z构成。我们设长度为n的所有串中所包含回文子串最少的数量为ans。问你长度为n,且包含回文子串数量为ans的串有多少种

    例如“aaaa” 的回文子串有 “a”, “aa”, “aaa” and “aaaa”.

    题解:

    n==1和n==2的答案都已给出

    n==3的时候   abc型、aab型、aaa型中所包含子回文串数量都一样是最少的,所以n==3时候答案是26*26*26

    之后就是找规律,这里直接说答案,如果一个串是abcabcabc...这样的串,它的回文串数量最少。(为什么它是最少的,,,这个你自己尝试比较比较就得出答案了)

    那么n>3之后的答案就是A263

    代码:

    #include <cstdio>
    #include <algorithm>
    #include <iostream>
    #include <vector>
    #include <map>
    #include <queue>
    #include <set>
    #include <ctime>
    #include <cstring>
    #include <cstdlib>
    #include <math.h>
    using namespace std;
    const int N = 1005;
    typedef long long ll;
    const int maxn = 1e6 + 5;
    ll bas[65], cnt;
    //int a[maxn];
    int q[maxn];
    //map<int, int> vis;
    vector<int> vec;
    char stack[maxn];
    char s[maxn];
    int a[maxn], dp[maxn];
    ll ksm(ll a, ll b, ll mod)
    {
        ll res = 1;
        while (b)
        {
            if (b & 1)
                res = (res * (a % mod)) % mod;
            a = ((a % mod) * (a % mod)) % mod;
            b >>= 1;
        }
        return res;
    }
    int main()
    {
        ll t;
        cin >> t;
        while (t--)
        {
            ll n;
            cin >> n;
            if (n == 1)
            {
                cout << 26ll << endl;
            }
            else if (n == 2)
            {
                cout << 676ll << endl;
            }
            else if (n == 3)
            {
                cout << 26 * 26 * 26 << endl;
            }
            else
            {
                cout<<26*25*24<<endl;
            }
        }
    }
  • 相关阅读:
    英式音标
    音标
    JavaWeb中文件的上传和下载
    SpringMVC简单实例(看起来有用)
    C语言指针的初始化和赋值
    VC++ CopyFile函数使用方法
    未将对象引用设置到对象的实例--可能出现的问题总结
    strip 命令的使用方法
    css3 animation动画事件
    CSS中的几个概念--------Day39
  • 原文地址:https://www.cnblogs.com/kongbursi-2292702937/p/13383818.html
Copyright © 2020-2023  润新知