http://poj.org/problem?id=2774 我想看看这里的后缀数组:http://blog.csdn.net/u011026968/article/details/22801015 本文主要讲下怎么hash去找 開始的时候写的是O(n^2 logn)算法 果断超时. ..尽管也用了二分的.. 代码例如以下: //hash+二分 #include <cstdio> #include <cstring> #include <algorithm> #incl…
Long Long Message Time Limit: 4000MS   Memory Limit: 131072K Total Submissions: 25752   Accepted: 10483 Case Time Limit: 1000MS Description The little cat is majoring in physics in the capital of Byterland. A piece of sad news comes to him these days…
一定好好学SAM...模板在此: #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<queue> #include<cstring> #define PAU putchar(' ') #define ENT putchar('\n') using namespace std; +,sig=; struct SAM{ stru…
后缀数组很久很久以前就出现了,具体的概念读者自行搜索,小菜仅略知一二,不便讨论. 本文通过寻找两个字符串的最长公共子字符串,演示了后缀数组的经典应用. 首先需要说明,小菜实现的这个后缀数组算法,并非标准,只是借鉴了其中的思想. 小菜实现的算法,有两个版本,第一个是空间换时间,第二个是时间换空间. 空间换时间版本 /* 利用后缀数组获取两个字符串最长公共子字符串 空间换时间版本 @params s1 String,要分析的字符串 s2 String,要分析的字符串 norepeat Boolean…
uva 10066 The Twin Towers 标题效果:最长公共子. 解题思路:最长公共子. #include<stdio.h> #include<string.h> #include<stdlib.h> #include<algorithm> using namespace std; int a[105], b[105], dp[105][105]; int main() { int n, m, Case = 1; while (scanf(&quo…
POJ 1458 最长公共子序列 题目大意:给出两个字符串,求出这样的一 个最长的公共子序列的长度:子序列 中的每个字符都能在两个原串中找到, 而且每个字符的先后顺序和原串中的 先后顺序一致. Sample Input : abcfbc abfcab programming contest abcd mnp Sample Output 4 2 0 分析: 输入两个串s1,s2, 设dp(i,j)表示: s1的左边i个字符形成的子串,与s2左边的j个 字符形成的子串的最长公共子序列的长度(i,j从…
Description A palindrome is a symmetrical string, that is, a string read identically from left to right as well as from right to left. You are to write a program which, given a string, determines the minimal number of characters to be inserted into t…
真的就是讲课两天,吸收一个月呢! \(1.\)虚树 \(2.\)KD-Tree \(3.\)长链剖分 \(4.\)后缀数组 后缀数组 \(5.\)后缀自动机 后缀自动机…
题意:求最长公共子串 思路:把两个串Hash,然后我们把短的作为LCS的最大可能值,然后二分长度,每次判断这样二分可不可以.判断时,先拿出第一个母串所有len长的子串,排序,然后枚举第二个母串len长度字串,二分查找在第一个母串的子串中存不存在. 代码: #include<cmath> #include<stack> #include<queue> #include<cstdio> #include<vector> #include<cst…
思考:其实很easy.就在两个串在一起.通过一个特殊字符,中间分隔,然后找到后缀数组的最长的公共前缀.然后在两个不同的串,最长是最长的公共子串. 注意的是:用第一个字符串来推断是不是在同一个字符中,刚開始用了第二个字符的长度来推断WA了2发才发现. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<map> #include<…