zoukankan      html  css  js  c++  java
  • [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)))即可,满足单调性。

     

    代码在此

  • 相关阅读:
    java:选择排序
    java:快速排序
    MYSQL 5.7版本修改密码
    多级代理下获取客户端真实IP
    map相关操作:map遍历,map转换为list
    【导航】微信开发者相关网址导航
    【java】微信开发后台官方后台配置篇
    HTML页面加载loading
    表单JS提交失效
    后台request获得所有参数(当你不知道它包含什么参数)
  • 原文地址:https://www.cnblogs.com/reverymoon/p/8903541.html
Copyright © 2011-2022 走看看