URAL1960 Palindromes and Super Abilities
Input
Output
Example
input | output |
---|---|
|
|
按顺序每次添加一个字符,求当前本质不同的回文串的数量
回文自动机
刚开始没意识到“本质不同”,加了个统计出现次数……
- /*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 ...
随机推荐
- js获取整型数组最大值、最小值、平均值
---恢复内容开始--- let values = [];//数组(整型数字) //获取数组最大值function arrMaxNum(arr){ var maxNum = null; for (va ...
- 2018年江西理工大学C语言程序设计竞赛(高级组) 三角平方数
题目描述 三角数:形如图a,圆点摆放成等边三角形的数字,则为三角数. (图a) 平方数:形如图b,小方块摆放成正方形的数字,则为平方数. (图b) 那么如果一个数字既是三角形数又是平方数,则称为三角平 ...
- (PowerDesigner&Sqlite)PD中设计完表后,将其导入数据库中
本人连接过SQLServer跟SQLite Ⅰ.SQLServer,百度,转一下:http://jingyan.baidu.com/article/7f766daf465e9c4101e1d0d5.h ...
- day 16 JS DOM 继续
为什么有jquey了还学DOM ? 因为JQuey 是大而全,可能有10k 但是我们用到的只有1k 网站小没事,网站大流量就是问题 所以大网站都是自己用DOM 实现一个类似于JQuey 的适合自己 ...
- luogu3195 [HNOI2008]玩具装箱TOY
懒得写 #include <iostream> #include <cstdio> using namespace std; typedef long long longliv ...
- kubernetes大概的工作原理
先放一张Kubernetes的架构图: 整体来看,是一个老大,多个干活的这种结构,基本上所有的分布式系统都是这样,但是里面的组件名称就纷繁复杂,下面将一一解析. 1.元数据存储与集群维护 作为一个集群 ...
- Couchbase I
Couchbase第一印象(架构特性) 面向文档 保存的字节流总有一个 DOCUMENT ID(Object_ID) 高并发性,高灵活性,高拓展性,容错性好 面向文档的集群存储系统 每个文档用一个唯一 ...
- IOS开发学习笔记008-预处理
预处理 1.宏定义 2.条件编译 3.文件包含 注意: 1.所有预处理都是以#开头,并且结尾不用分号. 2.宏名一般用大写字母,以便与变量名区别开来,但用小写也没有语法错误 3.作用域也是从定义到代码 ...
- 项目实战:CRM客户关系管理系统开发
21-CRM第一节内容概要 21.1 Stark组件介绍:实现基本的增删改查+自定义复杂操作: 21.2 单例模式:最简单的单例模式: 21.3 路由系统(分发): 21.4 制作启动文件-Djang ...
- vue tradingView(二)
tradingView 一些配置问题 tradingView 一些配置问题 javascript Demo_Hu 4月17日提问 · 4月17日更新 9 关注 1 收藏,993 浏览 问题对人有帮助, ...