[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 --- 后缀数组的更多相关文章

  1. Poj 3261 Milk Patterns(后缀数组+二分答案)

    Milk Patterns Case Time Limit: 2000MS Description Farmer John has noticed that the quality of milk g ...

  2. POJ 3261 Milk Patterns 后缀数组求 一个串种 最长可重复子串重复至少k次

    Milk Patterns   Description Farmer John has noticed that the quality of milk given by his cows varie ...

  3. POJ-3261 Milk Patterns,后缀数组+二分。。

                                                        Milk Patterns 题意:求可重叠的至少重复出现k次的最长的字串长. 这题的做法和上一题 ...

  4. 【poj 3261】Milk Patterns 后缀数组

    Milk Patterns 题意 给出n个数字,以及一个k,求至少出现k次的最长子序列的长度 思路 和poj 1743思路差不多,二分长度,把后缀分成若干组,每组任意后缀公共前缀都>=当前二分的 ...

  5. poj3261 Milk Patterns 后缀数组求可重叠的k次最长重复子串

    题目链接:http://poj.org/problem?id=3261 思路: 后缀数组的很好的一道入门题目 先利用模板求出sa数组和height数组 然后二分答案(即对于可能出现的重复长度进行二分) ...

  6. POJ3261 Milk Patterns —— 后缀数组 出现k次且可重叠的最长子串

    题目链接:https://vjudge.net/problem/POJ-3261 Milk Patterns Time Limit: 5000MS   Memory Limit: 65536K Tot ...

  7. BZOJ 1717 [USACO06DEC] Milk Patterns (后缀数组+二分)

    题目大意:求可重叠的相同子串数量至少是K的子串最长长度 洛谷传送门 依然是后缀数组+二分,先用后缀数组处理出height 每次二分出一个长度x,然后去验证,在排序的后缀串集合里,有没有连续数量多于K个 ...

  8. POJ 3261 Milk Patterns(后缀数组+单调队列)

    题意 找出出现k次的可重叠的最长子串的长度 题解 用后缀数组. 然后求出heigth数组. 跑单调队列就行了.找出每k个数中最小的数的最大值.就是个滑动窗口啊 (不知道为什么有人写二分,其实写啥都差不 ...

  9. POJ 3261 Milk Patterns ( 后缀数组 && 出现k次最长可重叠子串长度 )

    题意 : 给出一个长度为 N 的序列,再给出一个 K 要求求出出现了至少 K 次的最长可重叠子串的长度 分析 : 后缀数组套路题,思路是二分长度再对于每一个长度进行判断,判断过程就是对于 Height ...

随机推荐

  1. XMLHttpRequest 整理

    看了SF 上的一篇文章感触颇深:你真的会使用XMLHttpRequest吗? 在这我写上我读后的笔记: <!DOCTYPE html> <html lang="en&quo ...

  2. IDEA常见错误

    1. inspects a maven model for resolution problems 在添加Maven依赖的时候,报了inspects a maven model for resolut ...

  3. Hive ORC表的使用

    创建普通临时表: create table if not exists test_orc_tmp(   name string,   gender string,   cnt BIGINT )row ...

  4. [Leetcode] Longest Palindromic Subsequence

    Longest Palindromic Subsequence 题解 题目来源:https://leetcode.com/problems/longest-palindromic-subsequenc ...

  5. linux下route命令--说的比较清楚!

    linux下route命令     route命令感觉很不容易.一般开机后在命令行中使用route命令,会得到下面的信息   Kernel IP routing table   Destination ...

  6. mysql触发器(Trigger)简明总结和使用实例

    一,什么触发器 1,个人理解触发器,从字面来理解,一触即发的一个器,简称触发器(哈哈,个人理解),举个例子吧,好比天黑了,你开灯了,你看到东西了.你放炮仗,点燃了,一会就炸了.2,官方定义触发器(tr ...

  7. HTML+CSS图文排版

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...

  8. JS中firstChild,lastChild,nodeValue属性

    childNodes 在JavaScript中,使用childNodes属性可以返回一个数组,这个数组包含给定元素节点的全体子节点. firstChild firstChild 这句代码等价于 目标元 ...

  9. [你必须知道的.NET]第二十三回:品味细节,深入.NET的类型构造器

    发布日期:2008.11.2 作者:Anytao © 2008 Anytao.com ,Anytao原创作品,转贴请注明作者和出处. 说在,开篇之前 今天Artech兄在<关于Type Init ...

  10. mysql建立自增主键的插入,及自动插入当前时间

    MYSQL里用这两个字段,几乎都是必须的. 以前都是自动建立的,现在手把手建立的时候,就要找资料来搞定了. 参考URL: http://blog.csdn.net/Weicleer/article/d ...