3676: [Apio2014]回文串

Time Limit: 20 Sec  Memory Limit: 128 MB

Submit: 1680  Solved: 707

[Submit][Status][Discuss]

Description

考虑一个只包含小写拉丁字母的字符串s。我们定义s的一个子串t的“出 

现值”为t在s中的出现次数乘以t的长度。请你求出s的所有回文子串中的最 

大出现值。

Input

输入只有一行,为一个只包含小写字母(a -z)的非空字符串s。

Output

输出一个整数,为逝查回文子串的最大出现值。

Sample Input

【样例输入l】


abacaba



【样例输入2]

www


Sample Output

【样例输出l】


7



【样例输出2]

4
回文树模板题
#include <iostream>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <stdlib.h> using namespace std;
typedef long long int LL;
const int maxn=3e5+10;
char str[maxn];
struct Tree
{
int next[maxn][26];
int fail[maxn];
int num[maxn];
LL cnt[maxn];
int len[maxn];
int s[maxn];
int p;
int n;
int last;
int new_node(int x)
{
memset(next[p],0,sizeof(next[p]));
cnt[p]=0;
num[p]=0;
len[p]=x;
return p++;
}
void init()
{
p=0;
new_node(0);
new_node(-1);
last=0;n=0;
s[0]=-1;
fail[0]=1;
}
int get_fail(int x)
{
while(s[n-len[x]-1]!=s[n])
x=fail[x];
return x;
}
int add(int x)
{
x-='a';
s[++n]=x;
int cur=get_fail(last);
if(!(last=next[cur][x]))
{
int now=new_node(len[cur]+2);
fail[now]=next[get_fail(fail[cur])][x];
next[cur][x]=now;
num[now]=num[fail[now]]+1;
last=now;
}
cnt[last]++;
}
void count()
{
for(int i=p-1;i>=0;i--)
cnt[fail[i]]+=cnt[i];
}
}tree;
int main()
{
while(scanf("%s",str)!=EOF)
{
int len=strlen(str);
tree.init();
for(int i=0;i<len;i++)
tree.add(str[i]);
tree.count();
LL ans=0;
for(int i=2;i<tree.p;i++)
ans=max(ans,(LL)tree.cnt[i]*tree.len[i]);
printf("%lld\n",ans);
}
return 0;
}

最新文章

  1. Linq的分页与组合查询的配合使用
  2. php工作笔记6-手机端适应缩放
  3. 用JS识别各版本浏览器
  4. Halcon与MFC交互编程
  5. phoenix与spark整合
  6. git版本控制器
  7. 设计模式初学者笔记:Factory Method模式
  8. MD5Encoder加密支持utf-8
  9. html DOM 变化 通知,很好很强大
  10. How to define Servlet filter order of execution using annotations
  11. 【转】【阮一峰的网络日志】Git 使用规范流程
  12. 《A First Course in Probability》-chaper5-连续型随机变量-基本概念
  13. 怎么用C#获取Scenario step在specflow里
  14. Android开发实现透明通知栏
  15. Apache JMeter--网站自动测试与性能测评
  16. Leetcode题解(27)
  17. Jmeter之Non HTTP response code: java.net.SocketException/Non HTTP response message: Permission denied: connect
  18. Numpy 系列(九)- 结构化数组
  19. C#中抽象类和接口的区别与使用
  20. pair work结对编程(张艺 杨伊)

热门文章

  1. MongoDB Query 判断为空 取值为空的时间
  2. 未设置BufferSize导致FTP下载速度过慢的问题
  3. macbook的终端中使用gnu的ls命令
  4. Nginx日志深入详解
  5. clone和lambda的一个小问题和解决
  6. 文件上传之 commons-fileupload(一)
  7. Errors occurred while updating the change sets for SVNStatusSubscriber org.apache.subversion.javahl.
  8. 1.1 Application Fundamentals - 应用原理
  9. cocos2dx触摸
  10. PHP——smarty模板(第一天)