读题,我们知道选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. ping命令基于ICMP协议的返回信息分析

    Ping是潜水艇人员的专用术语,表示回应的声纳脉冲,在网络中 Ping 是一个十分好用的 TCP/IP 工具.它主要的功能是用来检测网络的连通情况和分析网络速度.可以利用 PING 命令检查网络连通状 ...

  2. The Preliminary Contest for ICPC Asia Shenyang 2019 C Dawn-K's water (完全背包)

    完全背包为什么要取到M,可以取到2*M嘛,这题需要整取,对于不能整取的背包容量,dp[k]=INF,以及dp[j-water[i].weight]=INF时,dp[j]也不需要更新.如果不整取的话,后 ...

  3. github是什么,有什么用

    转载连接:https://blog.csdn.net/obkoro1/article/details/68066441 写在前面:关于github的文章我已经写了两篇了,关于github个人网站搭建和 ...

  4. Educational Codeforces Round 75 (Rated for Div. 2)D(二分)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;pair<int,int>a[20 ...

  5. redis-py相关

    一 redis客户端命令 cmd进入redis客户端管理程序路径xx:\windows redis\redis-2.4.0-win32-win64\64bit 执行:redis-cli.exe -h ...

  6. MySQL的多表查询学习笔记

    一.案例准备 create table dept( id int primary key auto_increment, name ) ); insert into dept values(null, ...

  7. workspace 打开的是我的电脑

    在system tree板块的空白处右键-->set root-->current workspace 即可恢复workspace.

  8. notepad++ java编码,输出中文字符时,编译出错

    呆在公司中,最近受开发手机app的几个同事影响,想学android的开发,心血来潮,挡也挡不住,说干就干,直接看教程,发现有很多关于java的语法知识不懂,于是又来学java,学习的过程中难免出现问题 ...

  9. 单点登录--sso系统

    SSO英文全称Single Sign On,单点登录.SSO是在多个应用系统中,用户只需要登录一次就可以访问所有相互信任的应用系统.它包括可以将这次主要的登录映射到其他应用中用于同一个用户的登录的机制 ...

  10. PyQt5的菜单栏、工具栏和状态栏

    1.创建菜单栏import sys, mathfrom PyQt5.QtWidgets import *from PyQt5.QtGui import *from PyQt5.QtCore impor ...