读题,我们知道选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. socketserver模块(实现并发)

    socketserver模块(实现并发) 一.基于UDP协议实现的并发 # 服务端 import socketserver class MyServer(socketserver.BaseReques ...

  2. dfs+枚举,flip游戏的拓展POJ2965

    POJ 2965             The Pilots Brothers' refrigerator Description The game “The Pilots Brothers: fo ...

  3. 猜解数据库(MYSQL)信息

    /Less-1/?id=1' and if (length(database())=8,sleep(5),0) --+ 注:http://43.247.91.228:84/Less-1/为靶场地址,发 ...

  4. MySQL基本查询

    1.查询某数据库中表的总数 select count(*) from information_schema.tables where table_schema='dbname'; 2.仅占一列显示某数 ...

  5. vscode 提示 Running save participants 无法保存文件

    今天vscode提示一直在running save participants...中,无法保存文件 control + shift + p打开面板后,输入Reload with extensions ...

  6. uniGUI之UniPopupMenu和右键菜单(27)

    0]MainModule的BrowserOptions.boDisableMouseRightClick设置为Trure; 1]控件的OnCellContextClick的事件 procedure T ...

  7. CAN总线学习笔记

    1.CAN总线信息包的格式 问题: 1.CAN总线的初始化要初始化哪些东西? 2.处理器如何与CAN总线之间进行连接? 硬件连接 关于CC2底盘CAN通信的协议格式 备注: 设备地址为01 功能码

  8. 翻页插件 jquery

    //css <style> * { padding:; margin:; list-style: none; } .wrapper { width: 100%; cursor: point ...

  9. CentOS上安装elasticsearch

    1.安装docker yum install docker 2.启动docker systemctl start docker 查看docker版本: docker -v 之后只要启动机器就会自动开启 ...

  10. redhat7.6 httpd 匿名目录 目录加密 域名跳转

    配置文件/etc/httpd/conf/httpd.conf 监听80端口和8080端口 1.80端口 2.域名 3.index.html目录 4.网站目录 options Indexes   //代 ...