[USACO06FEC]Milk Patterns --- 后缀数组
[USACO06FEC]Milk Patterns
题目描述:
Farmer John has noticed that the quality of milk given by his cows varies from day to day.
On further investigation, he discovered that although he can't predict the quality of milk from one day to the next,
there are some regular patterns in the daily milk quality.
To perform a rigorous study, he has invented a complex classification scheme by which each milk sample is recorded as an integer between 0 and 1,000,000 inclusive,
and has recorded data from a single cow over N (1 ≤ N ≤ 20,000) days.
He wishes to find the longest pattern of samples which repeats identically at least K (2 ≤ K ≤ N) times.
This may include overlapping patterns -- 1 2 3 2 3 2 3 1 repeats 2 3 2 3 twice, for example.
Help Farmer John by finding the longest repeating subsequence in the sequence of samples.
It is guaranteed that at least one subsequence is repeated at least K times.
输入格式:
Line 1: Two space-separated integers: N and K
Lines 2..N+1: N integers, one per line, the quality of the milk on day i appears on the ith line.
输出格式:
Line 1: One integer, the length of the longest pattern which occurs at least K times
翻译:
农夫John发现他的奶牛产奶的质量一直在变动。
经过细致的调查,他发现:虽然他不能预见明天产奶的质量,但连续的若干天的质量有很多重叠。
我们称之为一个“模式”。 John的牛奶按质量可以被赋予一个0到1000000之间的数。
并且John记录了N(1<=N<=20000)天的牛奶质量值。
他想知道最长的出现了至少K(2<=K<=N)次的模式的长度。
比如1 2 3 2 3 2 3 1 中 2 3 2 3出现了两次。当K=2时,这个长度为4。
非常经典的后缀数组
先求出\(sa,rank,height\)三个数组
二分一个长度\(p\)
根据\(p\)来给后缀分类,具体而言,有公共前缀的一定会排到一起。
所以我们也可以知道对于某个子串,以它为公共前缀的后缀数组一定排到一起。
并且这些后缀数组连续的\(height\)超过\(len(string)\)的数量就是这个子串的出现次数。
因此,存在一个子串出现超过\(k\)次 ------> 根据\(height\)数组分出来的后缀数量有一组大于\(k\)
要求最长长度怎么办?
二分长度(\(len(string)\))即可,满足单调性。
[USACO06FEC]Milk Patterns --- 后缀数组的更多相关文章
- Poj 3261 Milk Patterns(后缀数组+二分答案)
Milk Patterns Case Time Limit: 2000MS Description Farmer John has noticed that the quality of milk g ...
- POJ 3261 Milk Patterns 后缀数组求 一个串种 最长可重复子串重复至少k次
Milk Patterns Description Farmer John has noticed that the quality of milk given by his cows varie ...
- POJ-3261 Milk Patterns,后缀数组+二分。。
Milk Patterns 题意:求可重叠的至少重复出现k次的最长的字串长. 这题的做法和上一题 ...
- 【poj 3261】Milk Patterns 后缀数组
Milk Patterns 题意 给出n个数字,以及一个k,求至少出现k次的最长子序列的长度 思路 和poj 1743思路差不多,二分长度,把后缀分成若干组,每组任意后缀公共前缀都>=当前二分的 ...
- poj3261 Milk Patterns 后缀数组求可重叠的k次最长重复子串
题目链接:http://poj.org/problem?id=3261 思路: 后缀数组的很好的一道入门题目 先利用模板求出sa数组和height数组 然后二分答案(即对于可能出现的重复长度进行二分) ...
- POJ3261 Milk Patterns —— 后缀数组 出现k次且可重叠的最长子串
题目链接:https://vjudge.net/problem/POJ-3261 Milk Patterns Time Limit: 5000MS Memory Limit: 65536K Tot ...
- BZOJ 1717 [USACO06DEC] Milk Patterns (后缀数组+二分)
题目大意:求可重叠的相同子串数量至少是K的子串最长长度 洛谷传送门 依然是后缀数组+二分,先用后缀数组处理出height 每次二分出一个长度x,然后去验证,在排序的后缀串集合里,有没有连续数量多于K个 ...
- POJ 3261 Milk Patterns(后缀数组+单调队列)
题意 找出出现k次的可重叠的最长子串的长度 题解 用后缀数组. 然后求出heigth数组. 跑单调队列就行了.找出每k个数中最小的数的最大值.就是个滑动窗口啊 (不知道为什么有人写二分,其实写啥都差不 ...
- POJ 3261 Milk Patterns ( 后缀数组 && 出现k次最长可重叠子串长度 )
题意 : 给出一个长度为 N 的序列,再给出一个 K 要求求出出现了至少 K 次的最长可重叠子串的长度 分析 : 后缀数组套路题,思路是二分长度再对于每一个长度进行判断,判断过程就是对于 Height ...
随机推荐
- 【CodeForces】704 B. Ant Man
[题目]B. Ant Man [题意]给定n个人的xi,ai,bi,ci,di,起点为s,终点为e,移动: In simpler words, jumping from i-th chair to j ...
- c++都忘记了,看了看那本发黄的C++primer,还是要去翻下了
char *s="string"和char s[]="string"的区别 void main() { char* pStr1 = "Hello!&q ...
- 【洛谷 P3965】 [TJOI2013]循环格(费用流)
题目链接 回路限制经典题. 每个点拆成入点和出点,源点连每个点的出点,流量1,费用0,每个点出点连汇点,流量1,费用0,入点和出点之间没有边. 也就是说每个点必须靠其他点流来的流量来流入汇点,同时自己 ...
- windows+python3.6下安装fasttext+fasttext在win上的使用+gensim(fasttext)
真是坑了好久,faxttext对win并不是很友好,所以遇到了很多坑,记录下来,以供大家少走弯路. 法1:刚开始直接用pip install fasttext,最后一直报下面这个错误 “error:M ...
- PHP分页类分享
/** * 获取分页的HTML内容 * @param integer $page 当前页 * @param integer $pages 总页数 * @param string $url 跳转url地 ...
- linux下C语言实现的内存池【转】
转自:http://blog.chinaunix.net/uid-28458801-id-4254501.html 操作系统:ubuntu10.04 前言: 在通信过程中,无法知道将会接收到的 ...
- elk系列6之tcp模块的使用【转】
preface tcp模块的使用场景如下: 有一台服务器A只需要收集一个日志,那么我们就可以不需要在这服务器上安装logstash,我们通过在其他logstash上启用tcp模块,监听某个端口,然后我 ...
- Ubuntu 各版本的几个国内更新源
Ubuntu 国内更新源(各版本通用) 前言:为了下载更方便,速度更快,我们在使用Linux系列系统时修改 apt源 为国内的源 1.复制源文件备份,以防万一 修改文件sources.list,在目录 ...
- 安装scrapy 出错 building 'twisted.test.raiser' extension error: Microsoft Visual C++ 14.0 is required.
安装Scrapy出现错误: building 'twisted.test.raiser' extension error: Microsoft Visual C++ 14.0 is required. ...
- (转)Opencv卷积操作
转自:http://www.2cto.com/kf/201312/267308.html Mask Operation filter2D函数 Last Edit 2013/12/24 所谓的Mask ...