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. eShopOnWeb 知多少

    1.引言 eShopOnWeb是基于ASP.NET Core构建,官方创建这样一个示例项目的目的,我想无非以下几点: 推广ASP.NET Core 指导利用ASP.NET Core如何进行架构设计 普 ...

  2. SUSE12SP3-Zookeeper安装

    直接使用root账号 1.zookeeper安装 将zookeeper-3.4.13.tar.gz安装包放置指定目录 sudo tar -zxvf zookeeper-3.4.13.tar.gz -C ...

  3. 【反编译系列】三、反编译神器(jadx)

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 概述 今天在看玩Android网站,搜索反编译的时候,才发现有个更好用的反编译工具.特此记录下. 下载 http://www.wanand ...

  4. 【java线程池】

    一.概述 1.线程池的优点 ①降低系统资源消耗,通过重用已存在的线程,降低线程创建和销毁造成的消耗: ②提高系统响应速度,当有任务到达时,无需等待新线程的创建便能立即执行: ③方便线程并发数的管控,线 ...

  5. 探索js原型链和vue构造函数中的奥妙

    这篇文章首先会讲到原型链以及原型链的一些概念,然后会通过分析vue的源码,来看一下vue的构造函数是如何被创建的,now we go! 一.什么是原型链? 简单回顾下构造函数,原型和实例的关系:   ...

  6. 【我们一起写框架】MVVM的WPF框架(一)—序篇

    前言 我想,有一部分程序员应该是在二三线城市的,虽然不知道占比,但想来应该不在少数. 我是这部分人群中的一份子. 我们这群人,面对的客户,大多是国内中小企业,或者政府的小部门.这类客户的特点是,资金有 ...

  7. Shell从入门到精通进阶之四:流程控制

    流程控制是改变程序运行顺序的指令. 4.1 if语句 4.1.1 单分支 if 条件表达式; then 命令 fi 示例: #!/bin/bash N=10 if [ $N -gt 5 ]; then ...

  8. Hadoop+Hbase分布式集群架构“完全篇”

    本文收录在Linux运维企业架构实战系列 前言:本篇博客是博主踩过无数坑,反复查阅资料,一步步搭建,操作完成后整理的个人心得,分享给大家~~~ 1.认识Hadoop和Hbase 1.1 hadoop简 ...

  9. Spring Cloud 系列之 Eureka 实现服务注册与发现

    如果你对 Spring Cloud 体系还不是很了解,可以先读一下 Spring Cloud 都有哪些模块 Eureka 是 Netflix 开源的服务注册发现组件,服务发现可以说是微服务架构的核心功 ...

  10. ASP.net<a>标签跨页面传参数

    //在goodsDetail.aspx页面接收 <script> //加载事件 $(function () { //第一种方式 var id=GetQueryString("id ...