Codeforces Round #621 (Div. 1 + Div. 2) C. Cow and Message

传送门

题目要求子串最大的数目是多少,且要求下标满足等差数列。(英语不好的我第一次写硬是没看出来那几个单词是等差数列的意思)

很明显,当我们选择的字串长度为1 or 2时,我们不用考略等差数列的要求。当长度大于2时一定得先构建长度为2的字串且还要增加限制,所以数量一定会变小。

#include<bits/stdc++.h>
using namespace std;
 
#define de(x) cout << #x << " == " << x << endl
 
typedef long long LL;         
typedef pair<int, int> P;
 
const int maxn = 1e5 + 10;        
const int M_MAX = 50000 + 10;
const int mod = 1e9;
const int INF = 0x3f3f3f3f;    
const double eps = 1e-6;      

LL dp[30][30], cnt[30];

void solve() {
    string s; 
    cin >> s;
    int sz = s.size();
    for(int i = 0; i < sz; i++) {
        for(int j = 0; j < 26; j++) {
            dp[j][s[i]-'a'] += cnt[j];
        }
        cnt[s[i]-'a']++;
    }
    LL res = 0;
    for(int i = 0; i < 26; i++) res = max(res, cnt[i]);
    for(int i = 0; i < 26; i++) {
        for(int j = 0; j < 26; j++) {
            res = max(res, dp[j][i]);
        }
    } 
    cout << res << endl;
}
 
int main() {
    ios::sync_with_stdio(false);
    //srand(time(NULL));    //更新种子
    solve();
    return 0;
}  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值