博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Milk Patterns poj3261(后缀数组)
阅读量:6307 次
发布时间:2019-06-22

本文共 2187 字,大约阅读时间需要 7 分钟。

Milk Patterns
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 9274   Accepted: 4173
Case Time Limit: 2000MS

Description

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.

Input

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.

Output

Line 1: One integer, the length of the longest pattern which occurs at least 
K times

Sample Input

8 212323231

Sample Output

4
1 #include 
2 #include
3 #include
4 using namespace std; 5 #define N 20001 6 #define M 1000002 7 int a[N],c[N],d[N],e[N],sa[N],height[N],n,b[M],m,k; 8 int cmp(int *r,int a,int b,int l) 9 {10 return r[a]==r[b]&&r[a+l]==r[b+l];11 }12 void da()13 {14 int i,j,p,*x=c,*y=d,*t;15 memset(b,0,sizeof(b));16 for(i=0; i
=0; i--)sa[--b[x[i]]]=i;19 for(j=1,p=1; p
=j)y[p++]=sa[i]-j;23 for(i=0; i
=0; i--)sa[--b[e[i]]]=y[i];28 for(t=x,x=y,y=t,p=1,x[sa[0]]=0,i=1; i
=n)return 0;47 sum=1;48 while(i
=mid)49 {50 sum++;51 i++;52 }53 if(sum>=k)return 1;54 }55 }56 int main()57 {58 int i,l,r;59 scanf("%d%d",&n,&k);60 for(i=0; i
>1;70 if(check(mid))71 l=mid+1;72 else r=mid-1;73 }74 printf("%d\n",r);75 }
View Code

 

转载于:https://www.cnblogs.com/ERKE/p/3593785.html

你可能感兴趣的文章
阶乘因式分解(一) 给定两个数m,n,其中m是一个素数。 将n(0<=n<=10000)的阶乘分解质因数,求其中有多少个m。 输入第一行是一个整数s(0<s<=100),表示测试数据的组数 ...
查看>>
20120515传智学习
查看>>
第7周
查看>>
NYOJ-36 最长公共子序列 AC 分类: NYOJ ...
查看>>
第一次作业
查看>>
C# 判断access建库、建表、文件是否存在等
查看>>
抢月饼 浏览器插件开发
查看>>
JavaScript - 倒计时
查看>>
CSS属性Vertical Align使用方法讲解
查看>>
微信授权文件放到域名根目录下
查看>>
Android-Service概念和用途
查看>>
Web.Config配置
查看>>
44. Wildcard Matching
查看>>
使用JQ实现相同行或列合并
查看>>
java实现反向代理服务器
查看>>
本周工作量及进度统计
查看>>
ZOJ 1542 Network(Kruskal)
查看>>
17个Web前端开发工程师必看的国外网站
查看>>
Oracle案例10——HWM(高水位线)性能优化
查看>>
中英文混合分词
查看>>