题意:求字符串的可重叠的k次最长重复子串

n<=20000 a[i]<=1000000

思路:后缀数组+二分答案x,根据height分组,每组之间的height>=x

因为可以重叠,所以只要判断是否有一组的height个数>=k即可

 var sa,rank,x,y,a,wc,wd,height:array[..]of longint;
n,m,i,l,r,mid,last,k1:longint; procedure swap(var x,y:longint);
var t:longint;
begin
t:=x; x:=y; y:=t;
end; function cmp(a,b,l:longint):boolean;
begin
exit((y[a]=y[b])and(y[a+l]=y[b+l]));
end; procedure getsa(n:longint);
var i,j,p:longint;
begin
for i:= to n- do
begin
x[i]:=a[i];
inc(wc[a[i]]);
end;
for i:= to m- do wc[i]:=wc[i-]+wc[i];
for i:=n- downto do
begin
dec(wc[x[i]]);
sa[wc[x[i]]]:=i;
end;
j:=; p:=;
while p<n do
begin
p:=;
for i:=n-j to n- do
begin
y[p]:=i; inc(p);
end;
for i:= to n- do
if sa[i]>=j then begin y[p]:=sa[i]-j; inc(p); end;
for i:= to n- do wd[i]:=x[y[i]];
for i:= to m- do wc[i]:=;
for i:= to n- do inc(wc[wd[i]]);
for i:= to m- do wc[i]:=wc[i-]+wc[i];
for i:=n- downto do
begin
dec(wc[wd[i]]);
sa[wc[wd[i]]]:=y[i];
end;
for i:= to n do swap(x[i],y[i]);
p:=; x[sa[]]:=;
for i:= to n- do
if cmp(sa[i-],sa[i],j) then x[sa[i]]:=p-
else begin x[sa[i]]:=p; inc(p); end;
j:=j*;
m:=p;
end;
end; procedure getheight(n:longint);
var i,k,j:longint;
begin
for i:= to n do rank[sa[i]]:=i;
k:=;
for i:= to n- do
begin
if k> then dec(k);
j:=sa[rank[i]-];
while a[i+k]=a[j+k] do inc(k);
height[rank[i]]:=k;
end;
end; function isok(x:longint):boolean;
var s,i:longint;
begin
s:=;
for i:= to n do
begin
if height[i]<x then
begin
if s>=k1 then exit(true);
s:=;
end
else inc(s);
end;
if s>=k1 then exit(true);
exit(false);
end; begin while not eof do
begin
fillchar(a,sizeof(a),);
fillchar(sa,sizeof(sa),);
fillchar(rank,sizeof(rank),);
fillchar(x,sizeof(x),);
fillchar(y,sizeof(y),);
fillchar(height,sizeof(height),);
fillchar(wc,sizeof(wc),);
fillchar(wd,sizeof(wd),);
readln(n,k1);
if n= then break;
for i:= to n- do
begin
read(a[i]);
inc(a[i]);
end;
a[n]:=; m:=;
getsa(n+);
getheight(n);
l:=; r:=n; last:=;
while l<=r do
begin
mid:=(l+r)>>;
if isok(mid) then begin last:=mid; l:=mid+; end
else r:=mid-;
end;
writeln(last);
// for i:= to n do writeln(height[i]);
end; end.

【BZOJ1717&POJ3261】Milk Patterns(后缀数组,二分)的更多相关文章

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

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

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

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

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

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

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

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

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

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

  6. poj 3261 Milk Patterns 后缀数组 + 二分

    题目链接 题目描述 给定一个字符串,求至少出现 \(k\) 次的最长重复子串,这 \(k\) 个子串可以重叠. 思路 二分 子串长度,据其将 \(h\) 数组 分组,判断是否存在一组其大小 \(\ge ...

  7. [USACO06FEC]Milk Patterns --- 后缀数组

    [USACO06FEC]Milk Patterns 题目描述: Farmer John has noticed that the quality of milk given by his cows v ...

  8. POJ3261 Milks patterns(后缀数组)

    Farmer John has noticed that the quality of milk given by his cows varies from day to day. On furthe ...

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

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

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

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

随机推荐

  1. iOS自带TTS技术的实现即语音播报

    文本转语音技术, 也叫TTS, 是Text To Speech的缩写. iOS如果想做有声书等功能的时候, 会用到这门技术. 一,使用iOS自带TTS需要注意的几点: iOS7之后才有该功能 需要 A ...

  2. CF962E Byteland, Berland and Disputed Cities

    思路: http://codeforces.com/blog/entry/58869. 实现: #include <bits/stdc++.h> using namespace std; ...

  3. (3)《Head First HTML与CSS》学习笔记---CSS入门

    1.O‘Reilly的<CSS PocketReference>是一本不错的CSS参考小书,记录了常用的元素属性. 2.元素选择器的作用强于继承的作用:用户定义强于浏览器默认(以下所有讨论 ...

  4. liunx 中安装mysql 图形界面 phpmyadmin

    是浏览器图形界面 1. 安装mysql 图形管理工具. 2. 使用phpmyadmin 图像化工具. 3.下载地址  http://www.phpmyadmin.net/ 4. 查看是否安装这两个包 ...

  5. ecpg - 嵌入的 SQL C 预处理器

    SYNOPSIS ecpg [ option...] file... DESCRIPTION 描述 ecpg 是一个嵌入的用于C 语言的 SQL 预编译器. 它把嵌有 SQL 语句的 C 程序通过将 ...

  6. zabbix 报警通知选项配置

    {TRIGGER.STATUS} host: {HOSTNAME} IP: {HOST.IP} events_time:{EVENT.DATE} {EVENT.TIME} notice_time:{D ...

  7. ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath

    问题: ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the ...

  8. python:第一章

    完成同一个任务,C语言要写1000行代码,Java只需要写100行,而Python可能只要20行. 代码少的代价是运行速度慢,C程序运行1秒钟,Java程序可能需要2秒,而Python程序可能就需要1 ...

  9. git-忽略文件改动不进行提交

    命令:git update-index --assume-unchanged 文件名 作用:忽略文件的改动,但是不加入.gitignore 文件中,这样可以达到仅在本地目录中忽略,不影响其他团队成员的 ...

  10. svn 设置代理

    Memory4Young Do Not Repeat Yourself! SVN —— 如何设置代理 如果在使用SVN下载外网的资源时,出现这样的提示:No such host is known. 或 ...