【题目链接】 http://poj.org/problem?id=3415 【题目大意】 求出两个字符串长度大于k的公共子串的数目。 【题解】 首先,很容易想到O(n2)的算法,将A串和B串加拼接符相连, 做一遍后缀数组,把分别属于A和B的所有后缀匹配,LCP-k+1就是对答案的贡献, 但是在这个基 ...
分类:
编程语言 时间:
2016-11-16 01:31:42
阅读次数:
191
【题目链接】 http://www.spoj.com/problems/SUBST1/ 【题目大意】 给出一个串,求出不相同的子串的个数。 【题解】 对原串做一遍后缀数组,按照后缀的名次进行遍历, 每个后缀对答案的贡献为n-sa[i]+1-h[i], 因为排名相邻的后缀一定是公共前缀最长的, 那么就 ...
分类:
编程语言 时间:
2016-11-15 23:49:35
阅读次数:
357
题意 给一个字符串,找出其子串可化为回文串的个数,子串可以任意改变其顺序。 思路 遍历每一个子串,若子串长度为奇数且只有一个字母的个数为奇数 或 字串长度为偶数且所有字母个数为偶数,则此子串为所求串。 总结 刚开始漏看了题,导致题意读错。 挺简单一道题,比赛时不记得怎样遍历每个子串。 对自己有点信心 ...
分类:
其他好文 时间:
2016-09-28 02:17:18
阅读次数:
210
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively. Below is one possible representati ...
分类:
其他好文 时间:
2016-09-20 12:11:35
阅读次数:
121
Description ?? is practicing his program skill, and now he is given a string, he has to calculate the total number of its distinct substrings. But ?? ...
分类:
编程语言 时间:
2016-08-28 01:13:16
阅读次数:
232
Common Substrings Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 10002 Accepted: 3302 Description A substring of a string T is defined as: ...
分类:
其他好文 时间:
2016-08-18 23:29:03
阅读次数:
229
Distinct Substrings Time Limit: 159MS Memory Limit: 1572864KB 64bit IO Format: %lld & %llu Description Given a string, we need to find the total numbe ...
分类:
其他好文 时间:
2016-08-16 23:37:20
阅读次数:
144
题目地址:传送门
D - Two Substrings
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d
& %I64u
Submit Status
Description
You are given string s. Your task i...
分类:
其他好文 时间:
2016-08-16 14:46:55
阅读次数:
144
题目链接:点击打开链接
思路:
我们用d[i]表示长度为i的答案。 那么我们可以把样例数据写出来看看是否能够递推。 可以发现, d[i] = d[i-1] - last[i-1] + (n-i+1) - dist[i]。
last[i]表示从后往前i长度时不同数字的个数, 也就是说, d[i-1]的最后一个子序列被扔了, 然后d[i]比d[i-1]还可能多加了( n - i + 1)...
分类:
其他好文 时间:
2016-08-08 21:12:26
阅读次数:
180
Problem Description In this problem, you are given a string s and q queries.For each query, you should answer that when all distinct substrings of str ...
分类:
编程语言 时间:
2016-08-07 11:00:54
阅读次数:
201