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 ...
随机推荐
- ASP.NET Core模块化前后端分离快速开发框架介绍之2、快速创建一个业务模块
源码地址 GitHub:https://github.com/iamoldli/NetModular 演示地址 地址:https://nm.iamoldli.com 账户:admin 密码:admin ...
- 快速搭建FTP服务
Linux下ftp服务可以通过搭建vsftpd服务来实现,以CentOS为例,首先查看系统中是否安装了vsftpd,可以通过执行命令 rpm -qa | grep vsftpd 来查看是否安装相应的包 ...
- spring MVC体系结构和请求控制器
MVC处理过程 spring MVC架构模式都进行了分层设计如下 数据访问接口:DAO层 处理业务逻辑层:service层 数据实体:POJO 负责前端请求的接受并处理:servlet 负责前端页面展 ...
- html5支持drag的拖放排序插件sortable.js
html5支持drag的拖放排序插件sortable.js <script src="//cdnjs.cloudflare.com/ajax/libs/Sortable/1.5.1/S ...
- SHELL脚本的常规命令
**shell脚本的执行方式: 方法一:首先赋予x权限,再输入相对路径或绝对路径,./testdot.sh或/root/shell/testdot.sh 方法二:sh testdot.sh(会新开一个 ...
- 12、python中的函数(高阶函数)
一.高阶函数 函数实际上也是一个对象,所以也能由变量指向一个函数对象,实际上函数名就是一个变量名.那么函数是传入变量作为参数的,如果传入的变量指向的是函数对象,这种函数就叫高阶函数. 高阶函数就是传入 ...
- Diycode开源项目 Glide图片加载分析
1.使用Glide前的准备 1.1.首先要build.gradle中添加 github原地址点击我. 参考博客:Glide-开始! 参考博客:android图片加载库Glide的使用介绍. 参考博 ...
- OpenCV学习笔记(十) 直方图操作
直方图计算 直方图可以统计的不仅仅是颜色灰度, 它可以统计任何图像特征 (如 梯度, 方向等等).直方图的一些具体细节: dims: 需要统计的特征的数目, 在上例中, dims = 1 因为我们仅仅 ...
- Python协程详解(一)
yield有两个意思,一个是生产,一个是退让,对于Python生成器的yield来说,这两个含义都成立.yield这个关键字,既可以在生成器中产生一个值,传输给调用方,同时也可以从调用方那获取一个值, ...
- 【word ladder】cpp
题目: Given two words (beginWord and endWord), and a dictionary, find the length of shortest transform ...