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(动态规划)的更多相关文章

  1. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  2. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  3. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  4. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  5. 【CF1132F】Clear the String(动态规划)

    [CF1132F]Clear the String(动态规划) 题面 CF 题解 考虑区间\(dp\). 增量考虑,每次考虑最后一个字符和谁一起删去,然后直接转移就行了. #include<io ...

  6. CF 1131 E. String Multiplication

    E. String Multiplication 题意 分析: 从后往前考虑字符串变成什么样子. 设$S_i = p_1 \cdot p_2 \dots p_{i}$,最后一定是$S_{n - 1} ...

  7. E. String Multiplication

    E. String Multiplication time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  8. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  9. 【动态规划】【最短路】Codeforces 710E Generate a String

    题目链接: http://codeforces.com/problemset/problem/710/E 题目大意: 问写N个字符的最小花费,写一个字符或者删除一个字符花费A,将当前的字符数量翻倍花费 ...

随机推荐

  1. for in 使用

    // JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式. 易于人阅读和编写. var json = { "id": 1, "n ...

  2. c语言-自己写的库

    一.俗话说算法是程序的灵魂,这下面本人写了一部分常用算法,欢迎大家使用,并提出批评和指正,当然也可以改进或者添加. 1.这是自己实现的算法库头文件 #ifndef _INC_ALGORITHM #de ...

  3. Java读取excel表,getPhysicalNumberOfCells()和getLastCellNum区别

    excel表存入数据库,发现有时报数组下标越界异常.调试发现用了 getPhysicalNumberOfCells(),这个是用来获取不为空的的列个数. getLastCellNum是获取最后一个不为 ...

  4. Vue.js-04:第四章 - 页面元素样式的设定

    一.前言 前端开发中有三大件:HTML.CSS.JavaScript,在前面的学习中,不管是学习 Vue 的指令系统还是 Vue 的事件修饰符,主要还是针对的是我们在前端开发中的 JavaScript ...

  5. 《白帽子讲Web安全》- 学习笔记

    一.为何要了解Web安全 最近加入新公司后,公司的官网突然被Google标记为了不安全的诈骗网站,一时间我们信息技术部门成为了众矢之的,虽然老官网并不是我们开发的(因为开发老官网的前辈们全都跑路了). ...

  6. FloatingActionButtonDemo【悬浮按钮的使用,顺带snackBar的使用】

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 FloatingActionButton简称FAB. 一. 对于App或某个页面中是否要使用FloatingActionButton ...

  7. [翻译]Mock 在 Python 中的使用介绍

    目录 Mock 在 Python 中的使用介绍 原文链接与说明 恐惧系统调用 一个简单的删除函数 使用 Mock 重构 潜在陷阱 向 'rm' 中加入验证 将文件删除作为服务 方法 1:模拟实例的方法 ...

  8. 浅谈SpringMVC执行过程

    通过深入分析Spring源码,我们知道Spring框架包括大致六大模块, 如Web模块,数据库访问技术模块,面向切面模块,基础设施模块,核心容器模块和模块, 其中,在Spring框架的Web模块中,又 ...

  9. Jetson Nano Developer Kit

    The Jetson Nano Developer Kit is an AI computer for learning and for making. ​ 一个推理框架,用于部署模型到嵌入式设备. ...

  10. .net core中使用autofac进行IOC

    .net Core中自带DI是非常简单轻量化的,但是如果批量注册就得扩展,下面使用反射进行批量注册的 public void AddAssembly(IServiceCollection servic ...