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;
}