读题,我们知道选1个、选2个的时候是没有冲突的,大于2个的时候就有限制,那么我们观察是否可以把大于2个的情况都转换一下,可以发现,如果有一个串的长度大于2,且出现的次数大于2,那么,组成这个串里必定有一个长度为2的串,出现的次数大于2,那我们就可以把所有大于2的长度转换为长度为2的,这样题目转换成长度为1与长度为2的最大值,复杂度就是O(26*|s|),一般字符串dp都要考虑26个字母

#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL; LL dp1[], dp2[][]; void run_case() {
string str;
cin >> str;
for(int i = ; i < str.size(); ++i) {
int now = str[i] - 'a';
for(int j = ; j < ; ++j)
dp2[j][now] += dp1[j];
dp1[now]++;
}
LL ans = ;
for(int i = ; i < ; ++i) ans = max(ans, dp1[i]);
for(int i = ; i < ; ++i)
for(int j = ; j < ; ++j)
ans = max(ans, dp2[i][j]);
cout << ans;
} int main() {
ios::sync_with_stdio(false), cin.tie();
//cout.setf(ios_base::showpoint);cout.precision(10);
//int t; cin >> t;
//while(t--)
run_case();
cout.flush();
return ;
}

Codeforces1307C. Cow and Message的更多相关文章

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

    Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is ...

  2. R - Cow and Message CodeForces - 1307C

    思路对了,但是不会写. 等差数列长度不是1就是2,所以不是一个字母就是俩字母,一开始写的时候直接枚举两个字母,然后让次数相乘.这样是不对的,比如abaabb,字母ab的个数应该是3+2+2,因该是每一 ...

  3. Eclipse 4.2 failed to start after TEE is installed

    ---------------  VM Arguments---------------  jvm_args: -Dosgi.requiredJavaVersion=1.6 -Dhelp.lucene ...

  4. POJ3267 The Cow Lexicon(DP+删词)

    The Cow Lexicon Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9041   Accepted: 4293 D ...

  5. POJ 3267 The Cow Lexicon

    又见面了,还是原来的配方,还是熟悉的DP....直接秒了... The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submis ...

  6. POJ 3267:The Cow Lexicon(DP)

    http://poj.org/problem?id=3267 The Cow Lexicon Time Limit: 2000MS   Memory Limit: 65536K Total Submi ...

  7. The Cow Lexicon

    The Cow Lexicon Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8815 Accepted: 4162 Descr ...

  8. HDOJ-三部曲-1015-The Cow Lexicon

    The Cow Lexicon Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 131072/65536K (Java/Other) To ...

  9. POJ3267——The Cow Lexicon(动态规划)

    The Cow Lexicon DescriptionFew know that the cows have their own dictionary with W (1 ≤ W ≤ 600) wor ...

随机推荐

  1. pipreqs (找当前项目依赖的包)

    pipreqs pipreqs可以帮你找到当前项目的所有组件及其版本.就是当别人给你一个程序的时候,你要在自己电脑上运行起来,就需要安装程序所依赖的组件,总不能自己一个一个找吧. # 安装 pip3 ...

  2. yii2.0 ajax

    2.0用的参数是_csrf token = "<?php echo \Yii::$app->request->getCsrfToken()?>", $.aj ...

  3. C语言:计算并输出S=1+(1+2^0.5)+(1+2^0.5+3^0.5)...+(1+2^0.5+3^0.5+...+n^0.5)

    //计算并输出S=1+(1+2^0.5)+(1+2^0.5+3^0.5)...+(1+2^0.5+3^0.5+...+n^0.5) #include<math.h> #include< ...

  4. C语言:计算输出给定数组中每相邻两个元素的平均值的平方根之和。

    //计算输出给定数组中每相邻两个元素的平均值的平方根之和. #include <stdio.h> #include <math.h> ]) { double a,b,s=0.0 ...

  5. Euler Sums系列(三)

    \[\Large\sum_{n=1}^{\infty}\frac{\left(H_{n}^{(2)}\right)^{2}}{n^{2}}=\frac{19}{24}\zeta(6)+\zeta^{2 ...

  6. 吴裕雄 python 神经网络——TensorFlow pb文件保存方法

    import tensorflow as tf from tensorflow.python.framework import graph_util v1 = tf.Variable(tf.const ...

  7. js屏幕上下滚动条

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  8. 【转】centos升级curl版本

    1.安装repo rpm -Uvh http://www.city-fan.org/ftp/contrib/yum-repo/rhel6/x86_64/city-fan.org-release-2-1 ...

  9. centos7搭建hadoop2.10完全分布式

    本篇介绍在centos7中大家hadoop2.10完全分布式,首先准备4台机器:1台nn(namenode);3台dn(datanode) IP hostname 进程 192.168.30.141 ...

  10. 【C++初学者自学笔记三】哑元函数、缺省参数、内联函数(模块二,PS:需要用到重载函数)

    一,哑元函数:一个函数的参数只有类型没有名字的则这个参数称之为哑元.类似于void fun(int); 功能:1保持向前的兼容性,比方说我们需要做成一个成品,然后成品是会不断的更新第一代第二代,当我们 ...