Ural 2040 Palindromes and Super Abilities 2 回文自动机
来源:互联网 发布:载软件.net framework 编辑:程序博客网 时间:2024/04/29 04:34
题目大意:给定一个字符串,从左到右依次加入每个字符,问每加入一个字符之后本质不同的回文串的数量增加多少
http://blog.csdn.net/huyuncong/article/details/41181953
回文自动机OTZ
注意:
1.这道题必须把奇串和偶串分开建 如果通过插入分隔符的方式建在一起会MLE
2.把长度为500W的01串一个一个输出会T掉 存在一个char数组里一起输出就行了
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define M 5000005using namespace std;int n;char s[M],ans[M];namespace Palindrom_Automaton{struct Trie{Trie *son[2],*fail;int dpt;Trie() {}Trie(int _):dpt(_) {}}mempool[M],*C=mempool,*odd=new (C++)Trie(-1),*even=new (C++)Trie(0),*last=odd;bool Extend(int x){Trie *p=last;while( s[x-p->dpt-1]!=s[x] )p=p->fail;if(p->son[s[x]-'a']){last=p->son[s[x]-'a'];return false;}last=p->son[s[x]-'a']=new (C++)Trie(p->dpt+2);if(p==odd)last->fail=even;else{for(p=p->fail;p!=odd&&s[x-p->dpt-1]!=s[x];p=p->fail);if(s[x-p->dpt-1]==s[x])last->fail=p->son[s[x]-'a'];elselast->fail=odd;}return true;}}int main(){using namespace Palindrom_Automaton;int i;gets(s+1);n=strlen(s+1);even->fail=odd;for(i=1;i<=n;i++){if(Extend(i))ans[i]='1';elseans[i]='0';}puts(ans+1);return 0;}
0 0
- Ural 2040 Palindromes and Super Abilities 2 回文自动机
- URAL 2040 Palindromes and Super Abilities 2(回文树)
- 【后缀回文自动机】 URAL 1960 Palindromes and Super Abilities
- URAL 2040 Palindromes and Super Abilities 2
- Ural 2040 Palindromes and Super Abilities 2
- URAL 2040 Palindromes and Super Abilities 2 (Palindromic Tree)
- URAL 1960 Palindromes and Super Abilities (回文树)
- URAL 1960- Palindromes and Super Abilities (回文树)
- [ural 1960] Palindromes and Super Abilities
- URAL 1960 Palindromes and Super Abilities
- 【ural】1960. Palindromes and Super Abilities【Palindromic Tree】
- URAL 1960 Palindromes and Super Abilities (Palindromic Tree)
- URAL2040-Palindromes and Super Abilities 2
- Ural1960 Palindromes and Super Abilities
- URAL1960-Palindromes and Super Abilities
- ural1960Palindromes and Super Abilities(回文树)
- URAL 2059 Not common palindromes 回文自动机
- URAL 1635. Mnemonics and Palindromes
- mysql知识点
- Android很多地方用到线程——关键字synchronized的使用
- Android开启和关闭闪光灯
- Topcoder srm 653 div.2 500 - RockPaperScissorsMagicEasy(DP)
- Spring MVC 学习笔记 json格式的输入和输出
- Ural 2040 Palindromes and Super Abilities 2 回文自动机
- nginx负载均衡和lvs负载均衡的比较分析
- Excel冻结首行/首列
- ======Java中的SSL通信初步(1)======
- 通过拖动鼠标进行滚动的js插件
- MySQL数据库基本操作
- 第三周项目五数组作数据成员(2)
- cocostudio骨骼动画 -- 原点
- 我的博客开通了,这将是我的一个成长记录