Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication
Time Limit: 2000 mSec
Problem Description

Input

Output
Print exactly one integer — the beauty of the product of the strings.
Sample Input
3
a
b
a
Sample Output
3
题解:这个题的思维难度其实不大,需要维护什么东西很容易想到,或者说套路十分明显
1、字符串无限制条件下最大值
2、强制选择左端点/右端点的最大值
3、是否只有一种字符
基本上需要维护的量就是这些,不过写起来实在是非常麻烦,以我的代码能力短时间实在是写不出来,后来参考了一位大佬的代码,写的思路清晰,代码简洁,实在是非常值得学习,之所以能够使得代码变简洁,主要是因为他枚举了字母。题目明确说明只有小写英文字母,所以最后的最大值无非就是这26个字母中的一个形成的,因此分别计算各个字母对应的最大值即可算出最终最大值,而一旦固定了每次考虑取最大值的字母,写代码的难度会大大降低,关键点就这一条,直接上代码。
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 1; i <= (n); i++)
#define sqr(x) ((x) * (x)) const int maxn = + ;
const int maxm = + ;
const int maxs = + ; typedef long long LL;
typedef pair<int, int> pii;
typedef pair<double, double> pdd; const LL unit = 1LL;
const int INF = 0x3f3f3f3f;
const LL mod = ;
const double eps = 1e-;
const double inf = 1e15;
const double pi = acos(-1.0); int n;
int len[maxn];
string str[maxn]; int main()
{
ios::sync_with_stdio(false);
cin.tie();
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
cin >> n;
for (int i = ; i <= n; i++)
{
cin >> str[i];
len[i] = str[i].size();
}
int ans = ;
for (int c = ; c < ; c++)
{
int mx = , cnt = ;
for (int i = ; i < len[]; i++)
{
if (str[][i] - 'a' != c)
{
mx = max(mx, cnt);
cnt = ;
}
else
{
cnt++;
}
}
mx = max(mx, cnt);
for (int i = ; i <= n; i++)
{
int lmx = , rmx = ;
int nmx = ;
for (int j = ; j < len[i]; j++)
{
if (str[i][j] - 'a' == c)
lmx++;
else
break;
}
for (int j = len[i] - ; j >= ; j--)
{
if (str[i][j] - 'a' == c)
rmx++;
else
break;
}
cnt = ;
for (int j = ; j < len[i]; j++)
{
if (str[i][j] - 'a' != c)
{
nmx = max(nmx, cnt);
cnt = ;
}
else
cnt++;
}
nmx = max(nmx, cnt); if (nmx == len[i])
{
mx = (mx + ) * nmx + mx;
}
else
{
if (mx != )
mx = lmx + rmx + ;
else
mx = max(lmx, rmx);
}
mx = max(mx, nmx);
}
ans = max(ans, mx);
}
cout << ans << endl;
return ;
}
Codeforces #541 (Div2) - E. String Multiplication(动态规划)的更多相关文章
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- 【CF1132F】Clear the String(动态规划)
[CF1132F]Clear the String(动态规划) 题面 CF 题解 考虑区间\(dp\). 增量考虑,每次考虑最后一个字符和谁一起删去,然后直接转移就行了. #include<io ...
- CF 1131 E. String Multiplication
E. String Multiplication 题意 分析: 从后往前考虑字符串变成什么样子. 设$S_i = p_1 \cdot p_2 \dots p_{i}$,最后一定是$S_{n - 1} ...
- E. String Multiplication
E. String Multiplication time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- 【动态规划】【最短路】Codeforces 710E Generate a String
题目链接: http://codeforces.com/problemset/problem/710/E 题目大意: 问写N个字符的最小花费,写一个字符或者删除一个字符花费A,将当前的字符数量翻倍花费 ...
随机推荐
- Exp2后门原理与实践 20164312马孝涛
实验内容 使用netcat获取主机操作Shell,cron启动 (0.5分) 使用socat获取主机操作Shell, 任务计划启动 (0.5分) 使用MSF meterpreter(或其他软件)生成可 ...
- vue 对列表数组删除和增加
很重要,一定要好好研究 https://cn.vuejs.org/v2/guide/list.html#%E6%9B%BF%E6%8D%A2%E6%95%B0%E7%BB%84
- 【安富莱TCPnet网络教程】HTTP通信实例
第41章 HTTP超文本传输协议基础知识 本章节为大家讲解HTTP(HyperText Transfer Protocol,超文本传输协议),从本章节开始,正式进入嵌入式Web的设计和学习. ...
- C#实现将Chart图表生成JPG图片的方法
SaveFileDialog savefile= new SaveFileDialog(); savefile.Filter = "JPEG文件|*.jpg" ...
- markdown用法
Markdown 语法的目标是成为一种适用于网络的书写语言.不在 Markdown 涵盖范围之内的标签,都可以直接在文档里面用 HTML 撰写.不需要额外标注,只要直接加标签就可以了. 一.常用部分 ...
- pandas对Excel文件的读写操作
1.将Excel数据读为dataframe 1.1 直接读取 df = pd.read_excel('data.xlsx') 1.2 根据sheet索引 xls = pd.ExcelFile('dat ...
- 第4章 简单的C程序设计——选择结构程序设计
在顺序结构中,各语句是按自上而下的顺序执行的,执行完上一个语句就自动执行下一个语句,是无条件的,不必作任何判断.实际上,很多情况下,需要根据某个条件是否满足来决定是否执行指定的操作任务,或者从给定的两 ...
- perl学习笔记--搭建开发环境
windows下perl开发环境搭建 perl下载地址:http://www.activestate.com/developer-tools 各个插件的安装方法:(通过代理上网的方法) 方法一:pad ...
- 从一个国内普通开发者的视角谈谈Sitecore
一.Sitecore是个神马玩意 简而言之,Sitecore就是一个基于ASP.NET技术的CMS系统,它不仅具有传统Web CMS的所有功能,还集成了Marketing营销(当然,这个功能价格不菲) ...
- 【微信小程序项目实践总结】30分钟从陌生到熟悉
前言 我们之前对小程序做了基本学习: 1. 微信小程序开发07-列表页面怎么做 2. 微信小程序开发06-一个业务页面的完成 3. 微信小程序开发05-日历组件的实现 4. 微信小程序开发04-打造自 ...