博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
694. Distinct Substrings (后缀数组)
阅读量:7210 次
发布时间:2019-06-29

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

694. Distinct Substrings

Problem code: DISUBSTR

 

Given a string, we need to find the total number of its distinct substrings.

Input

T- number of test cases. T<=20;

Each test case consists of one string, whose length is <= 1000

Output

For each test case output one number saying the number of distinct substrings.

Example

Sample Input:

2
CCCCC
ABABA

Sample Output:

5
9

Explanation for the testcase with string ABABA: 

len=1 : A,B
len=2 : AB,BA
len=3 : ABA,BAB
len=4 : ABAB,BABA
len=5 : ABABA
Thus, total number of distinct substrings is 9.

 

 这个超时,有待检查:

#include
#include
#include
using namespace std;const int maxn=1010;char str[maxn];int wa[maxn],wb[maxn],wv[maxn],wn[maxn],a[maxn],sa[maxn];int cmp(int *r,int a,int b,int l){ return r[a]==r[b] && r[a+l]==r[b+l];}void da(int *r,int *sa,int n,int m){ int i,j,p,*x=wa,*y=wb,*t; for(i=0; i
=0; i--) sa[--wn[x[i]]]=i; for(j=1,p=1; p
=j) y[p++]=sa[i]-j; for(i=0; i
=0; i--) sa[--wn[wv[i]]]=y[i]; for(t=x,x=y,y=t,p=1,x[sa[0]]=0,i=1; i

 

 

AC:

#include
#include
#include
using namespace std;const int maxn=1010;char str[maxn];int wa[maxn],wb[maxn],wv[maxn],wn[maxn],a[maxn],sa[maxn];int cmp(int *r,int a,int b,int l){ return r[a]==r[b] && r[a+l]==r[b+l];}void da(int *r,int *sa,int n,int m){ int i,j,p,*x=wa,*y=wb,*t; for(i=0; i
=0; i--) sa[--wn[x[i]]]=i; for(j=1,p=1; p
=j) y[p++]=sa[i]-j; for(i=0; i
=0; i--) sa[--wn[wv[i]]]=y[i]; for(t=x,x=y,y=t,p=1,x[sa[0]]=0,i=1; i

 

转载地址:http://wvrum.baihongyu.com/

你可能感兴趣的文章
Spark综合使用及用户行为案例页面转化率统计分析实战-Spark商业应用实战
查看>>
Android Studio 3.2.0 正式版新特性
查看>>
JavaScript_JS里的函数:值和闭包
查看>>
Swift中遇到的警告--解决方法
查看>>
微信小程序学习笔记 路由传参
查看>>
Java 枚举查找并不抛异常的实现
查看>>
如何理解maxcompute常见报错信息?
查看>>
论如何获取 2 个多边形相交关系
查看>>
仿QQ阅读UI布局的搭建之感想
查看>>
Cocoapods 安装 (2019)
查看>>
浅谈Vue内置component组件的应用场景
查看>>
js发布订阅,vue里面也需要
查看>>
【LocustPlus序】漫谈服务端性能测试
查看>>
顺序程序代码分析
查看>>
MaxCompute,基于Serverless的高可用大数据服务
查看>>
flex布局
查看>>
React通过redux-persist持久化数据存储
查看>>
hibernate实体监听器
查看>>
怎么解决在微信中不能直接下载APP(APK)的方案
查看>>
你真的懂switch吗?聊聊switch语句中的块级作用域
查看>>