SPOJ - DISUBSTR 多少个不同的子串

如何把Excel的数据导入python? Python数据分析——excl导入数据的简单方法(xlrd) 本文的初衷是发现网上很多Excel导入Python都没有结合具体Excel文档进行讲解,所以这篇文档将会呈现一个简单快速的Excel+Python的入门方法。 开发环境 Prerequisites: 在开始用Python导入Excel之前,要配置好自己的开发环境,最好有IDE(terminal也可)+安装相应的数据分析包。 IDE :pycharm,vscode,etc 数据分析包:matplotlib,xlrd,numpy,etc 导入数 阅读详情

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.


/*
SPOJ - DISUBSTR 多少个不同的子串

求一个串中有多少个不同的子串

每个子串一定是某个后缀的前缀,那么原问题等价于求所有后缀之间的不相
同的前缀的个数。
height表示的公共前缀的长度 = 相同串的个数
所以  总数-sum(height[])即可
*/
#include <algorithm>
#include <cmath>
#include <queue>
#include <iostream>
#include <cstring>
#include <map>
#include <cstdio>
#include <vector>
#include <functional>
#define lson (i<<1)
#define rson ((i<<1)|1)
using namespace std;
typedef long long ll;
const int maxn = 1005;

int t1[maxn],t2[maxn],c[maxn];
bool cmp(int *r,int a,int b,int l)
{
    return r[a]==r[b] &&r[l+a] == r[l+b];
}

void get_sa(int str[],int sa[],int Rank[],int height[],int n,int m)
{
    n++;
    int p,*x=t1,*y=t2;
    for(int i = 0; i < m; i++) c[i] = 0;
    for(int i = 0; i < n; i++) c[x[i] = str[i]]++;
    for(int i = 1; i < m; i++) c[i] += c[i-1];
    for(int i = n-1; i>=0; i--) sa[--c[x[i]]] = i;
    for(int j = 1; j <= n; j <<= 1)
    {
        p = 0;
        for(int i = n-j; i < n; i++) y[p++] = i;
        for(int i = 0; i < n; i++) if(sa[i] >= j) y[p++] = sa[i]-j;
        for(int i = 0; i < m; i++) c[i] = 0;
        for(int i = 0; i < n; i++) c[x[y[i]]]++ ;
        for(int i = 1; i < m; i++) c[i] += c[i-1];
        for(int i = n-1; i >= 0; i--)  sa[--c[x[y[i]]]] = y[i];

        swap(x,y);
        p = 1;
        x[sa[0]] = 0;
        for(int i = 1; i < n; i++)
            x[sa[i]] = cmp(y,sa[i-1],sa[i],j)? p-1:p++;
        if(p >= n) break;
        m = p;
    }
    int k = 0;
    n--;
    for(int i = 0; i <= n; i++)
        Rank[sa[i]] = i;
    for(int i = 0; i < n; i++)
    {
        if(k) k--;
        int j = sa[Rank[i]-1];
        while(str[i+k] == str[j+k]) k++;
        height[Rank[i]] = k;
    }
}

int Rank[maxn],height[maxn];
int sa[maxn];
char str[maxn];
int a[maxn];
int n;

int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        int tot = 0;
        scanf("%s",str);
        int len = strlen(str);
        for(int i = 0;i < len; i++)
            a[i] = str[i];
        a[len] = 0;
        get_sa(a,sa,Rank,height,len,200);

        int ans = len*(len+1)/2;
        for(int i = 2; i <= len; i++)
        {
            //printf("%d ",height[i]);
            ans -= height[i];
        }
        cout << ans <<endl;
    }
    return 0;
}


星空组网 vs 蒲公英 vs Tailscale:2024年国内免费异地组网工具横评(含实测数据) 本文对2024年国内主流免费异地组网工具星空组网、蒲公英和Tailscale进行了深度横向评测。基于实测数据,重点分析了三者在P2P成功率、中继延迟、传输速度及稳定性方面的表现,为中小企业、远程办公及个人开发者提供了清晰的选择指南。星空组网在国内网络环境下展现出优秀的平衡性。 阅读详情

相关推荐

RK3588部署Zipformer模型问题总结

本文分享了在RK3588嵌入式设备上部署小米Zipformer语音识别模型时遇到的问题及解决方法。主要遇到两个问题:1)在rknn_model_zoo例程编译时出现静态库版本不兼容,通过重新编译kaldi-native-fbank库并修改链接路径解决;2)sherpa-onnx编译时提示缺少portaudio库,通过修改编译脚本启用相关宏定义后成功编译。最终成功在RK3588上运行Zipformer模型,测试结果显示该模型具有较好的识别效果和实时性(RTF=0.22),验证了其在边缘设备上的适用性。

pkyang2004的博客 2144

SPOJ DISUBSTR(后缀数组)

题意:给出了一个串s,问不相同的子串的个数。 题解:用求后缀数组的函数得到sa[i],height[i],按后缀字典序排好序,相邻的两个串可以得到的不同子串个数是len - sa[i] - height[i],这样把所有的相邻后缀串累加就得到所有不同子串个数。#include <cstdio> #include <cstring> #include <algorithm> #define F(x)

俯瞰风景 530

音视频开发—H264相关概念和压缩原理详解(GOP、宏块、帧内压缩、帧间压缩)

本文讲述了H264相关概念和原理——GOP概念,SPS与PPS,帧内压缩原理,帧间压缩原理,解释了什么是运动补偿,什么运动矢量等等概念

weixin_46999174的博客 3978

32_不同子串

【代码】32_不同子串。

成长需要沉淀。 445

MCU 微控制器,在实际项目中如何选型(以 STM32为例)

1.MCU 选型需要考虑的一些因素 2.案例:传感器设备的 MCU 选型

创享 AIOT 的专栏 1万+

避坑指南:SAP CO模块维护成本控制范围的5个常见错误及解决方法

本文深入剖析了SAP CO模块中维护成本控制范围时最易犯的5个常见错误,包括货币参数配置不当、标准层次结构缺失、财政年度变式不一致、功能激活遗漏及集成参数设置错误。重点针对事务码OKKP的配置,提供了详细的排查步骤与实战解决方案,帮助顾问有效规避陷阱,确保成本核算体系稳定运行。

stone的博客 233

不同子序列--动态规划完成

题目描述: 给定两个字符串S和T,求S有多少个不同的子串与T相同。S的子串定义为在S中任意去掉0个或者多个字符形成的串。子串可以不连续,但是相对位置不能变。比如“ACE”是“ABCDE”的子串,但是“AEC”不是。 解题思路: 假设S字符串为“rabbbit”,T字符串为“rabbit”,行为S字符串中取前 i 个字符,列为T字符串中取前 j 个字符...

Light丶Long的博客 297

CarSim仿真快速入门(十八)-CarSim2021中的混合动力和纯电动系统

CarSim和TruckSim包括用于电动汽车(BEV)和混合电动汽车(HEV)的动力总成系统。电动和混合电动系统可与所有现有驱动系统配合使用,例如:FWD,RWD,AWD和多轴驱动系统。混合动力/电动系统模型还包括电池管理控制。CarSim或TruckSim中的默认动力总成是为闭环速度控制器提供的备用动力总成。要安装和使用完整的动力总成,请从Vehicle: Assembly库或Vehicle: Lead Unit 库链接到Powertrain数据集。在“动力总成”界面上,从下拉列表控件中选择以下三个选项

小明师兄的博客 7455

【蓝桥杯省赛JavaB组真题详解】不同的子串(2019)

题目描述 不同的子串 一个字符串的非空子串是指字符串中长度至少为1 的连续的一段字符组成 的串。例如,字符串aaab 有非空子串a, b, aa, ab, aaa, aab, aaab,一共7 个。 注意在计算时,只算本质不同的串的个数。 请问,字符串0100110001010001 有多少个不同的非空子串? 这是一道结果填空的题,你只需要算出结果后提交即可。本题的结果为一 个整数,在提交答案时只填写这个整数,填写多余的内容将无法得分。 解题思路 用hashset会自动排除重复元素。 参考代码 import

疼疼蛇的博客 1380

用 SELECT FOR UPDATE 亲手制造典型数据库死锁——从 ABAP 视角揭秘 RDBMS 的锁争夺战

在日常 ABAP 开发中,多数人只在 ST22 里偶尔瞥见这行 dump,却对背后的原理知之甚少。本文借助社区前辈的经典实验,还原一个可复现的死锁现场,进一步讨论产生根因、检测手段与规避策略,并用真实业务案例串联起数据库、Open SQL 与 SAP NetWeaver 锁管理之间的逻辑链条。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 454

向华为学习——IPD流程体系之IPD术语

《IPD体系核心概念与业务术语解析》摘要: IPD(集成产品开发)是一种以市场为导向的结构化产品开发管理模式,通过跨部门协作、异步开发、CBB(通用构建模块)和管道管理等手段,实现产品全生命周期高效管理。体系包含七大核心要素:跨部门团队(如IPMT决策层、PDT执行层)、结构化流程(分阶段评审)、端到端项目管理(WBS分级计划)、客户需求分析、投资组合优化及质量管控(TR技术评审)。各业务领域术语涵盖财务(NPV、IRR)、开发(需求分解、基线化)、制造(可制造性设计)、采购(Sourcing团队)及市场(

cdfunlove的博客 480

不同子串[蓝桥杯2019初赛]

题目链接:不同子串 时间限制: 1 Sec 内存限制: 256 MB 题目描述: 一个字符串的非空子串是指字符串中长度至少为1 的连续的一段字符组成的串。 例如,字符串aaab 有非空子串a, b, aa, ab, aaa, aab, aaab,一共7 个。 注意在计算时,只算本质不同的串的个数。 请问,字符串0100110001010001 有多少个不同的非空子串? 题意:就是算出这个字符串有多少个非空子串。 思路:这种填空题,我们运行出结果后,把代码注释掉只打印运行结果即可。 代码: string

『愚』的博客 7831

基于FPGA的数字图像处理-直方图操作【3.3】

对于固定的位宽和图像分辨率来说,这个计算过程是 可定量的,也就是这个归一化系数是已知的。1.直方图累计和 根据数学定义,直方图累加和的定义是小于指定像素的所有像素 的统计值之和。在实际应用中,处理帧缓存是费时费力费资源的一件事情,在许 多情况下,图像的变换比较慢,在这种情况下的一个近似是当建立当 前帧的直方图统计结果时使用从前一帧得到的映射。由测试结果可见,这两幅过曝光和曝光不足的图像,经过均衡化 之后的效果图差别不大,对比度都非常高,设计代码达到了预期的均 衡目的。累加和的计算情况如图6-28所示。

qq_43416206的博客 1123

SPOJ DISUBSTR - Distinct Substrings or SUBST1 - New Distinct Substrings 【不同子串数目】

题目链接:SPOJ DISUBSTR - Distinct Substrings DISUBSTR - Distinct Substrings no tags Given a string, we need to find the total number of its distinct substrings. Input T- number of test cases. T Each

世界很大 752

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

SPOJ DISUBSTR - Distinct Substrings 后缀数组

原题:https://vjudge.net/problem/SPOJ-DISUBSTR 题解:求本质不同子串的个数,考虑用容斥原理,不同的答案就是总数减去相同的,重复的就是后缀数组中h的和即: #include&lt;cstdio&gt; #include&lt;cstring&gt; #include&lt;algorithm&gt; using namespace std; const ...

Exception 227

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

后缀数组模板(SPOJ - DISUBSTR)

是真的只是模板了,暂时没办法完全理解代码实现。 Distinct Substrings #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #define LL long long using namespace std; const int ...

SarenSage的博客 245

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

SPOJ DISUBSTR - Distinct Substrings(后缀数组[不相同的子串的个数])

SPOJ DISUBSTR - Distinct Substrings(后缀数组[不相同的子串的个数])

queuelovestack的专栏 1140

Distinct Substrings 【SPOJ - DISUBSTR】【后缀数组求不同子串个数】

题目链接 求不同子串的个数。 于是,我们可以考虑成,一个后缀,和它前一个sa的后缀有多少个不重叠的前缀子串。 #include <iostream> #include <cstdio> #include <cmath> #include <string> #include <cstring> #include <algorithm> #include <limits> #include <vector&..

既然弱小,就只顾变强就是了 309

SPOJ - DISUBSTR Distinct Substrings (后缀数组 不同子串个数)

Distinct Substrings 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 &...

YOONGI 219

spoj 694 求一个字符串中不同子串的个数

SPOJ Problem Set (classical) 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

芒果街上的小屋(此博客暂时停用) 1029

SPOJ 694 求不同子串数 后缀数组

题目链接:http://www.spoj.com/problems/DISUBSTR/ 题意: T个测试数据 每个测试数据一行:字符串,求该字符串有多少个不同的子串。   论文思路: 每个子串一定是某个后缀的前缀,那么原问题等价于求所有后缀之间的不相 同的前缀的个数。如果所有的后缀按照suffix(sa[1]), suffix(sa[2]), suffix(sa[3]), …… ,

九野的博客 2186

spoj 694 不相同的字串的个数 对后缀数组又了解了一些

SPOJ Problem Set (classical) 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.

hnust_xiehonghao的专栏 1120

SPOJ 694 / SPOJ DISUBSTR Distinct Substrings【后缀数组】不相同的子串的个数

Description Given a string, we need to find the total number of its distinct substrings. Input T- number of test cases. T Each test case consists of one string, whose length is Output For e

Joeferyの博客 521

SPOJ - DISUBSTR Distinct Substrings (后缀数组)

DISUBSTR - Distinct Substrings no tags  Given a string, we need to find the total number of its distinct substrings. Input T- number of test cases. T Each test case consists of one st

say_c_box的博客 403
上一篇: POJ 3261 可重叠k次最长重复子串
下一篇: URAL 1297 最长回文子串(后缀数组)
Tyuio28
博客等级 码龄11年 12粉丝 279原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值