URAL1960 Palindromes and Super Abilities
Input
Output
Example
input | output |
---|---|
aba |
1 2 3 |
按顺序每次添加一个字符,求当前本质不同的回文串的数量
回文自动机
刚开始没意识到“本质不同”,加了个统计出现次数……
/*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int mxn=;
int read(){
int x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
char s[mxn];
struct Pam{
int t[mxn][];
int l[mxn],sz[mxn],fa[mxn];
int res[mxn];
int S,cnt,last;
void init(){S=cnt=last=fa[]=fa[]=;l[]=-;return;}
void add(int c,int n){
int p=last;
while(s[n-l[p]-]!=s[n])p=fa[p];
if(!t[p][c]){
int np=++cnt;l[np]=l[p]+;
int k=fa[p];
while(s[n-l[k]-]!=s[n])k=fa[k];
fa[np]=t[k][c];//fail指针
t[p][c]=np;
}
last=t[p][c];
sz[last]++;//统计出现次数
}
void solve(){
printf("%d ",cnt-);
/*
memset(res,0,sizeof res);
int ans=0;
for(int i=cnt;i;i--){
res[i]+=sz[i];
res[fa[i]]+=res[i];
ans+=res[i];
}
printf("%d ",ans);*/
return;
}
}hw;
int main(){
int i,j;
scanf("%s",s+);
int len=strlen(s+);
hw.init();
for(i=;i<=len;i++){
hw.add(s[i]-'a',i);
hw.solve();
}
return ;
}
URAL1960 Palindromes and Super Abilities的更多相关文章
- URAL 2040 Palindromes and Super Abilities 2 (回文自动机)
Palindromes and Super Abilities 2 题目链接: http://acm.hust.edu.cn/vjudge/contest/126823#problem/E Descr ...
- Ural 2040. Palindromes and Super Abilities 2 回文自动机
2040. Palindromes and Super Abilities 2 题目连接: http://acm.timus.ru/problem.aspx?space=1&num=2040 ...
- 回文树(回文自动机) - URAL 1960 Palindromes and Super Abilities
Palindromes and Super Abilities Problem's Link: http://acm.timus.ru/problem.aspx?space=1&num=19 ...
- URAL 2040 Palindromes and Super Abilities 2(回文树)
Palindromes and Super Abilities 2 Time Limit: 1MS Memory Limit: 102400KB 64bit IO Format: %I64d ...
- Ural 1960 Palindromes and Super Abilities
Palindromes and Super Abilities Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged ...
- URAL 2040 Palindromes and Super Abilities 2
Palindromes and Super Abilities 2Time Limit: 500MS Memory Limit: 102400KB 64bit IO Format: %I64d &am ...
- 【URAL】1960. Palindromes and Super Abilities
http://acm.timus.ru/problem.aspx?space=1&num=1960 题意:给一个串s,要求输出所有的s[0]~s[i],i<|s|的回文串数目.(|s|& ...
- 回文树1960. Palindromes and Super Abilities
Bryce1010模板 http://acm.timus.ru/problem.aspx?space=1&num=1960 #include <bits/stdc++.h> usi ...
- Ural2040:Palindromes and Super Abilities(离线&manecher算法)
Dima adds letters s1, …, sn one by one to the end of a word. After each letter, he asks Misha to tel ...
随机推荐
- c++引用与指针的区别
c++引用与指针的区别 ★ 相同点: 1. 都是地址的概念: 指针指向一块内存,它的内容是所指内存的地址:引用是某块内存的别名. 指针的权威定义: In a declaration T D where ...
- Windows 下编辑 hosts 文件
hosts 文件目录: C:\WINDOWS\system32\drivers\etc\hosts hosts是一个没有扩展名的系统文件,可以用记事本等工具打开,其作用就是将一些常用的网址域名与其对应 ...
- Java 对数组的筛选
在Java里面 一般对一个数组进行筛选,去剔除一些元素,一般做法是用临时数组来存储,把符合条件的元素加入到新数组中,虽然数组有移除的方法但是 是线程不安全的: 而用迭代器Iterator,可以在遍历的 ...
- 【前端_js】解决ajax跨域请求数据
1.ajax发送请求必须遵循同源策略,即请求方和相应方的协议头.域名.端口全部一样.只要三者有一个不一样都视为跨域,浏览器出于安全考虑不允许跨域访问. 解决ajax跨域访问的常用方法: a.使用jso ...
- 十一、Shell 文件包含
Shell 文件包含 和其他语言一样,Shell 也可以包含外部脚本.这样可以很方便的封装一些公用的代码作为一个独立的文件. Shell 文件包含的语法格式如下: . filename # 注意点号( ...
- IDEA整合Mybatis+Struts2+Spring (二)--整合框架
二.搭建目录结构 我这里列出的是搭建完了之后所有的目录和文件,诸位先把目录文件建起来,然后我在给出文件内容 这里的目录建好之后还需要设置一下,让idea识别目录作用,选择File-Project St ...
- uncompressing linux .................................................后没反应解决办法
编译kernel是的no machine record defined 错误,网上有一些解法,其实都是错误的,以讹传讹.不打算自己写,找到一篇还算靠谱的,转摘一下. 其根本原因是没有在 __proc_ ...
- 模块numpy的用法
https://blog.csdn.net/qq351469076/article/details/78817378 机器学习三剑客之Numpy: https://www.jianshu.com/p/ ...
- du 与df 统计系统磁盘不一致原因与解决方法
事件起因: 同事发现云主机磁盘系统盘满了,准备清理系统盘,便利用du 命令统计了根目录下各文件夹的大小,发现统计的各文件夹的大小总和 加起来比 df 命令查看到的系统盘所使用空间 要小很多.这里记录下 ...
- B1051 复数乘法(15 分)
[PAT]B1051 复数乘法(15 分) - 路明天 - 博客园 https://www.cnblogs.com/hebust/p/9496809.html 在此对四舍五入输出结果做总结. 对于do ...