hdu3613
题解:
EX_KMP
网上似乎说kmp也可以,但是我交了一发代码没过
然后标记一下哪一些前缀和后缀会问
暴力枚举拆开了的位置
代码:
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
const int N=;
int v[],n,nxt[N],match[N],exnxt[N],exmatch[N];
int L[N],R[N];
char s[N],t[N];
void EXKMP(char s[],char t[],int n,int m)
{
exnxt[]=m;
for (int i=,po=;t[i];i++)
{
int P=po+exnxt[po];
exnxt[i]=max(min(exnxt[i-po],P-i),);
while (i+exnxt[i]<m&&t[exnxt[i]]==t[i+exnxt[i]])exnxt[i]++;
if (i+exnxt[i]>P) po=i;
}
for (int i=,po=;s[i];i++)
{
int P=po+exmatch[po];
exmatch[i]=max(min(exnxt[i-po],P-i),);
while (exmatch[i]<m&&i+exmatch[i]<n&&t[exmatch[i]]==s[i+exmatch[i]])exmatch[i]++;
if (i+exmatch[i]>P) po=i;
}
}
int main()
{
int T;
scanf("%d",&T);
while (T--)
{
memset(exmatch,,sizeof exmatch);
for (int i=;i<;i++) scanf("%d",&v[i]);
scanf("%s",&s);
n=strlen(s);
if (n<)
{
puts("");
continue;
}
for (int i=;i<n;i++)t[n--i]=s[i];
t[n]='\0';
L[]=v[s[]-'a'];
for (int i=;i<n;i++)L[i]=L[i-]+v[s[i]-'a'];
R[n-]=v[s[n-]-'a'];
for (int i=n-;i>=;i--)R[i]=R[i+]+v[s[i]-'a'];
EXKMP(s,t,n,n);
for (int i=;i<n;i++)R[i]=(exmatch[i]==n-i)?R[i]:;
EXKMP(t,s,n,n);
for (int i=;i<n;i++)L[i]=(exmatch[n--i]==i+)?L[i]:;
int ans=;
for (int i=;i<n-;i++)ans=max(ans,L[i]+R[i+]);
printf("%d\n",ans);
}
return ;
}
hdu3613的更多相关文章
- hdu3613 Best Reward 扩展kmp or O(n)求最大回文子串
/** 题目:hdu3613 Best Reward 链接:http://acm.hdu.edu.cn/showproblem.php?pid=3613 题意:有一个字符串,把他切成两部分. 如果这部 ...
- HDU3613 Best Reward —— Manacher算法 / 扩展KMP + 枚举
题目链接:https://vjudge.net/problem/HDU-3613 Best Reward Time Limit: 2000/1000 MS (Java/Others) Memor ...
- hdu3613 扩展KMP
#include<stdio.h> #include<string.h> #define maxn 501000 char s[maxn],t[maxn]; int next[ ...
- [扩展KMP][HDU3613][Best Reward]
题意: 将一段字符串 分割成两个串 如果分割后的串为回文串,则该串的价值为所有字符的权值之和(字符的权值可能为负数),否则为0. 问如何分割,使得两个串权值之和最大 思路: 首先了解扩展kmp 扩展K ...
- [Manacher][HDU3613][Best Reward]
题意: 将一段字符串 分割成两个串 如果分割后的串为回文串,则该串的价值为所有字符的权值之和(字符的权值可能为负数),否则为0. 问如何分割,使得两个串权值之和最大 思路: 裸的: 枚举分割点,计算, ...
- HDU3613 Manacher//EXKMP//KMP
http://acm.hdu.edu.cn/showproblem.php?pid=3613 每个字符都有一个权值,将一个字符串分成两半,如果某一半是回文串就把所有的字符权值加起来,否则当0来处理,问 ...
- hdu3613 Best Reward【Manacher】
Best Reward Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- hdu3613 Best Reward manacher+贪心+前缀和
After an uphill battle, General Li won a great victory. Now the head of state decide to reward him w ...
- kuangbin专题十六 KMP&&扩展KMP HDU3613 Best Reward(前缀和+manacher or ekmp)
After an uphill battle, General Li won a great victory. Now the head of state decide to reward him w ...
随机推荐
- win10 字体渲染优化 色彩调整
最近烧包买了个2k显示器,发现跟win10使用,一堆问题,最大的就是字体,其实应该买4k,那样正好设置200%字体,现在设置的124% 字体: 以前使用的是mactype这个软件 https://pa ...
- 项目梳理4——WebApi项目,使用注释填充Description字段
web.config中添加连接字符串: 为webapi添加Description,使用注释来填充此字段 对于所有引用的xxxx.base项目设置生成的xml文档,注意release.debug下都需设 ...
- org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected subelement profile
原创:转载请注明出处 1.异常情况 org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unexpected ...
- Ubuntu Eclipse ns3编译中 遇到的OSError 系列问题
问题1:Permission denied 解决方法:修改文件权限,利用 chmod 命令 修改在 /home/wasdns/workspace/MyNS3_Mac/ns-3.25 (eclipse工 ...
- apiCloud检出代码出现以下图示错误:
问题如下: Initialized empty Git repository in H:/simlpe/.git/ 已经在 H:\simlpe 完成必要的项目初始化工作正在尝试从代码服务器获取数据.. ...
- IntelliJ IDEA问题总结
在使用Idea的过程中,会遇到各种各样的问题,下面我将在这里持续总结: 1.Unable to import maven project: See logs for details 在遇到这个问题时, ...
- Mui --- 页面之间的传值
A页面 mui.ajax('http://14.50.2.49:80/default/AppLogin?Prm=' + Prm, { data: {}, //dataType: 'json', typ ...
- c++ 判断数组元素是否有负数(any_of)
#include <iostream> // std::cout #include <algorithm> // std::any_of #include <array& ...
- Codeforces 735B - Urbanization
735B - Urbanization 思路:贪心.人数少的城市住钱最多的那几个人. 不证明了,举个例子吧:a1<a2<a3<a4<a5 (a1+a2+a3)/3+(a4+a5 ...
- 只输FLOAT值 TEXTBOX
if (((int)e.KeyChar < 48 || (int)e.KeyChar > 57) && (int)e.KeyChar != 8 && (in ...