spoj694 DISUBSTR - 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 <= 1000 Output For each test case output one number saying the number of distinc…
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<=20;Each test case consists of one string, whose length is <= 1000 Output For each test case output…
New Distinct Substrings 题目大意 给定一个字符串,求本质不同的子串个数 题解 SA常见思想:每一个子串都是某个后缀的前缀 考虑每一个后缀的贡献,首先他拥有n - sa[i]个(我是用的模板中,sa[i]的大小是0....n-1)前缀,这些前缀有height[i]个跟sa[i-1]相同,要减去.剩下的部分不可能与sa[i-1]之前的想通了,不然sa[i]会排在sa[i-1]前面 还要注意本题的字符集是小写字母(鬼知道样例是什么东西) #include <cstdio> #…
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 distinc…
题意:统计母串中包含多少不同的子串 然后这是09年论文<后缀数组——处理字符串的有力工具>中有介绍 公式如下: 原理就是加上新的,减去重的,这题是因为打多校才补的,只能说我是个垃圾 #include <iostream> #include <cmath> #include <cstdio> #include <cstring> #include <cstdlib> #include <string> #include &l…
思路 求本质不同的子串个数,总共重叠的子串个数就是height数组的和 总子串个数-height数组的和即可 代码 #include <cstdio> #include <algorithm> #include <cstring> #define int long long const int MAXN = 100000; using namespace std; int height[MAXN],sa[MAXN],ranks[MAXN],barrel[MAXN],n;…
/* 统计每个节点的max和min, 然后求和即可 min = max[fa] + 1 */ #include<cstdio> #include<algorithm> #include<iostream> #include<cstring> #include<queue> #define ll long long #define M 6010 #define mmp make_pair using namespace std; int read(…
求不相同子串个数    该问题等价于求所有后缀间不相同前缀的个数..也就是对于每个后缀suffix(sa[i]),将贡献出n-sa[i]+1个,但同时,要减去那些重复的,即为height[i],故答案为n-sa[i]+1-height[i]的累计. ; var x,y,rank,sa,h,c:..maxn] of longint; s:ansistring; t,q,n:longint; function max(x,y:longint):longint; begin if x>y then e…
DISUBSTR - 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 <= 1000 Output For each test case output one nu…
DISUBSTR - Distinct Substrings 链接 题意: 询问有多少不同的子串. 思路: 后缀数组或者SAM. 首先求出后缀数组,然后从对于一个后缀,它有n-sa[i]-1个前缀,其中有height[rnk[i]]个被rnk[i]-1的后缀算了.所以再减去height[rnk[i]]即可. 代码: 换了板子. #include<cstdio> #include<algorithm> #include<cstring> #include<iostr…
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<=20; Each test case consists of one string, whose length is <= 1000 Output For each test case outpu…
DISUBSTR - Distinct Substrings 题意:给你一个长度最多1000的字符串,求不相同的字串的个数. 思路:一个长度为n的字符串最多有(n+1)*n/2个,而height数组已经将所有的重复的都计算出来了,直接减去就行.需要注意的是在字符串的最后面加个0,不参与Rank排名,这样得到的height数组直接从1到n. char s[N]; int sa[N],Rank[N],height[N],c[N],t[N],t1[N],n,m; void build(int n) {…
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 numbe…
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 distin…
SPOJ694 DISUBSTR 题目描述: Given a string, we need to find the total number of its distinct substrings. 输入格式: T- number of test cases. T<=20; Each test case consists of one string, whose length is <= 1000 输出格式: For each test case output one number sayin…
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 c…
Distinct Substrings Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on SPOJ. Original ID: DISUBSTR64-bit integer IO format: %lld      Java class name: Main   Given a string, we need to find the total number of its distinct subst…
Description 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 <= 50000 Output For each test case output one number saying the num…
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 <= 50000 Output For each test case output one number saying the number of disti…
705. New Distinct Substrings Problem code: SUBST1 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 <= 50000 Output For each test…
[SPOJ]Distinct Substrings(后缀自动机) 题面 Vjudge 题意:求一个串的不同子串的数量 题解 对于这个串构建后缀自动机之后 我们知道每个串出现的次数就是\(right/endpos\)集合的大小 但是实际上我们没有任何必要减去不合法的数量 我们只需要累加每个节点表示的合法子串的数量即可 这个值等于\(longest-shortest+1=longest-parent.longest\) #include<iostream> #include<cstdio&g…
[SPOJ]Distinct Substrings/New Distinct Substrings(后缀数组) 题面 Vjudge1 Vjudge2 题解 要求的是串的不同的子串个数 两道一模一样的题目 其实很容易: 总方案-不合法方案数 对于串进行后缀排序后 不合法方案数=相邻两个串的不合法方案数的和 也就是\(height\)的和 所以\[ans=\frac{n(n+1)}{2}-\sum_{i=1}^{len}height[i]\] #include<iostream> #include…
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 distinc…
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 <= 50000 Output For each test case output one number saying the number of disti…
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 <= 50000 Output For each test case output one number saying the number of disti…
D - New Distinct Substrings 题目大意:求一个字符串中不同子串的个数. 裸的后缀数组 #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define pii pair<int, int> #define y1 skldjfskldjg #define y2 skldfjsklejg using names…
New Distinct Substrings(后缀数组) 给定一个字符串,求不相同的子串的个数.\(n<=50005\). 显然,任何一个子串一定是后缀上的前缀.先(按套路)把后缀排好序,对于当前的后缀\(S_i\),显然他有\(n-sa[i]\)个前缀.其中,有\(height[i]\)个前缀字符串在编号比它小的后缀中出现过,因此它对答案的贡献是\(n-sa[i]-height[i]\). #include <cstdio> #include <cstring> usin…
\(\color{#0066ff}{ 题目描述 }\) 给定一个字符串,求该字符串含有的本质不同的子串数量. \(\color{#0066ff}{输入格式}\) T- number of test cases. T<=20; Each test case consists of one string, whose length is <= 50000 \(\color{#0066ff}{输出格式}\) For each test case output one number saying th…
Distinct Substrings 题意 求一个字符串有多少个不同的子串. 分析 又一次体现了后缀数组的强大. 因为对于任意子串,一定是这个字符串的某个后缀的前缀. 我们直接去遍历排好序后的后缀字符串(也就是 \(sa\) 数组),每遍历到一个后缀字符串,会新添数量为这个后缀字符串的长度的前缀,但是要减去 \(height[i]\),即公共前缀的长度,因为前面已经添加过了这个数量的前缀串. code #include<bits/stdc++.h> using namespace std;…
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 <= 50000 Output For each test case output one number saying the number of disti…