BZOJ3676: [Apio2014]回文串
2016-02-11 22:05
615 查看
PAM裸题
关于PAM怎么构造我之前有个链接
然后就是每次加num就好了
最后统计一下
我打的代码常数打的吓人
PAM:
还有一种方法很丑 是用manacher+SAM我不想打= =
关于PAM怎么构造我之前有个链接
然后就是每次加num就好了
最后统计一下
我打的代码常数打的吓人
PAM:
#include<cstdio> #include<iostream> #include<cstring> using namespace std; struct Node { int len; Node *ch[31]; Node *last; int num; Node(){for(len=0;len<=30;len++)ch[len]=NULL;last=NULL;len=num=0;} }; Node*Max_Node,*Node_2,*Node_1; int num; Node *Stack[400001]; int top; inline Node *New_Node() { Node *res=new Node; Stack[top++]=res; return res; } char s[400001]; inline void begin(){Node_2=new Node;Node_1=new Node;Max_Node=Node_2;num=2;Node_2->last=Node_1->last=Node_1;Node_1->len=-1;Node_2->len=0;} inline bool add(int place) { bool Exit=false; Node *cur=Max_Node; int curlen=0,son=s[place]-'a'; while(true) { curlen=cur->len; if(place-1-curlen>=0&&s[place-1-curlen]==s[place]) break; cur=cur->last; } if(cur->ch[son]) Max_Node=cur->ch[son],cur->ch[son]->num++; else { Exit=true; Node*tp=New_Node(); Max_Node=tp; tp->len=cur->len+2; cur->ch[son]=tp; if(tp->len==1) tp->last=Node_2,tp->num=1; else { while(true) { cur=cur->last; curlen=cur->len; if(place-1-curlen>=0&&s[place-1-curlen]==s[place]) { Max_Node->last=cur->ch[son]; break; } } Max_Node->num=1; } } return Exit; } long long ans=-1; inline void Calc() { Node *tp; for(int i=top-1;i!=-1;i--) { tp=Stack[i];tp->last->num+=tp->num; ans=max(ans,tp->num*1ll*tp->len); } } char c; int main() { int len=0; do c=getchar();while(c<'a'||c>'z'); while(c<='z'&&c>='a') s[len++]=c,c=getchar(); begin(); for(int i=0;i<len;i++)add(i); Calc(); printf("%lld\n",ans); return 0; }
还有一种方法很丑 是用manacher+SAM我不想打= =
相关文章推荐
- [linux] Linux的bg和fg命令简单介绍
- 三层ViewPager嵌套 的事件处理
- 静态库和动态库的使用
- Tomcat
- Android辅助功能AccessibilityService与抢红包辅助
- 欢迎使用CSDN-markdown编辑器
- HDU 1029 基础dp
- PCB设计之原理图绘制笔记
- socket 中的read
- iOS之运行时(Runtime)
- 2016/02/11
- Arcgis server java develop begining
- 安装win7和centos6.7双系统 记录
- Animator根运动清除刚体速率问题测试
- 图片画画板
- UIView的setNeedsDisplay和setNeedsLayout方法
- 任务栏浏览器主页被劫持
- Gradle教程Part2:java工程
- 链表ADT C语言实现
- hdu2457 DNA repair(AC自动机+dp)