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

http://codeforces.com/contest/1307/problem/C

给出一个字符串,在这个题目中的子序列定义为,出现次数必须是等差数列的序列,如:aaabb的其中一个子序列就是aab,其出现的位置是1 3 5,呈等差数列,现在问,在这个题目中出现次数最多的子序列,出现的次数是多少

刚看题的时候以为是模拟题,然后想模拟,但是发现那个等差数列并不会求,然后就jj

看完题解发现这是个思维题,简直了。。。。而且巨简单

是对答案有贡献的子序列,长度不是 1 就是 2 ,因为自己举了几个例子后发现,如果存在一个长度大于 2 的子序列,那么其长度必定可以拆成长度为 1 的或者长度为 2 的,这样一来我们就发现等差数列的这个条件也就变成了烟雾弹,因为长度为 1 和长度为 2 的子序列无论如何组合,都肯定是等差数列。

所以题目就变成了了找长度为1的或者长度为2的。

#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include<iomanip>
#define SIS std::ios::sync_with_stdio(false)
#define ll long long
#define INF 0x3f3f3f3f
const int mod = 1e9 + 7;
const double esp = 1e-5;
const double PI = 3.141592653589793238462643383279;
using namespace std;
const int N = 1e7 + 5;
const int maxn = 1 << 20;
/**************************************/
char s[N];
ll cnt[40][42], cc[40], ans;
int main() {
	scanf("%s", s);
	int n = strlen(s);
	for (int i = 0; i < n; i++) {
		int w = s[i] - 'a';
		for (int j = 0; j < 26; j++)
			cnt[w][j] += cc[j];
		cc[w]++;
	}
	for (int i = 0; i < 26; i++)//长度为2的最大值
		for (int j = 0; j < 26; j++)
			ans = max(ans, cnt[i][j]);
	for (int i = 0; i < 26; i++)//长度为1的最大值
		ans = max(ans, cc[i]);
	cout << ans << endl;
}


 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

deebcjrb

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值