博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SCOJ 4484 The Graver Robbers' Chronicles 后缀自动机
阅读量:4679 次
发布时间:2019-06-09

本文共 2318 字,大约阅读时间需要 7 分钟。

4484: The Graver Robbers' Chronicles

题目连接:

Description

One day, Kylin Zhang and Wu Xie are trapped in a graveyard. They find an ancient piece of parchment with a cipher string.

After discussion and analysis, they find the password is the total number of the cipher string's distinct substrings.
Although Kylin Zhang is powerful and always help his friends get rid of danger, this time he is helpless beacause
he is not good at math and programming.
As a smart Acmer, can you help them solve this problem so that they can escape from this horrible graveyard.

Input

The first line is an integer T stands for the number of test cases.

Then T test case follow.
For each test case there is one string.

Constraints:

T is no bigger than 30.
The length of string is no bigger than 50000.
Every string only contains lowercase letters.

Output

For each test case, output the answer in a single line. one number saying the number of distinct substrings.

Sample Input

2

aaaaa
cacac

Sample Output

5

9

Hint

题意

给你一个串,问你有多少个不同的子串

题解:

后缀自动机/后缀数组裸题

枚举结尾的字符的最长后缀,减掉和自己父亲重合的位置就好了。

代码

#include
using namespace std;const int maxn = 50100;char s1[maxn];struct SAM { struct { int len, f, ch[26]; void init() { len = 0, f = -1; memset(ch, 0xff, sizeof (ch)); } } e[maxn<<1]; int idx, last; void init() { idx = last = 0; e[idx++].init(); } int newnode() { e[idx].init(); return idx++; } void add(int c) { int end = newnode(); int tmp = last; e[end].len = e[last].len + 1; for (; tmp != -1 && e[tmp].ch[c] == -1; tmp = e[tmp].f) { e[tmp].ch[c] = end; } if (tmp == -1) e[end].f = 0; else { int nxt = e[tmp].ch[c]; if (e[tmp].len + 1 == e[nxt].len) e[end].f = nxt; else { int np = newnode(); e[np] = e[nxt]; e[np].len = e[tmp].len + 1; e[nxt].f = e[end].f = np; for (; tmp != -1 && e[tmp].ch[c] == nxt; tmp = e[tmp].f) { e[tmp].ch[c] = np; } } } last = end; }};SAM sam;void solve(){ scanf("%s",s1); int len = strlen(s1); sam.init(); for(int i=0;i

转载于:https://www.cnblogs.com/qscqesze/p/5403486.html

你可能感兴趣的文章
Android模拟器无法上网访问网络失败解决办法
查看>>
node启动时, listen EADDRINUSE 报错;
查看>>
vue学习链接
查看>>
Systemd 初始化进程
查看>>
【C#学习笔记】文本复制到粘贴板
查看>>
Windows store 验证你的 URL http:// 和 https:// ms-appx:/// ms-appdata:///local
查看>>
python全栈开发_day7_字符编码,以及文件的基本读取
查看>>
js 验证码 倒计时60秒
查看>>
C#基础
查看>>
ASP.NET Core MVC 2.x 全面教程_ASP.NET Core MVC 15. 用户管理
查看>>
杭电3466————DP之01背包(对状态转移方程的更新理解)
查看>>
算法分析常用记号
查看>>
spring mvc 返回类型
查看>>
[js高手之路] html5 canvas动画教程 - 匀速运动
查看>>
11.VS2015常用快捷键大全
查看>>
js学习总结----less常用的方法
查看>>
需求分析问卷调查及反馈结果
查看>>
当深度学习遇见自动文本摘要
查看>>
心随手动,驱动短视频热潮的引擎
查看>>
Servlet深入之初始化
查看>>