博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj3261 -- Milk Patterns
阅读量:7106 次
发布时间:2019-06-28

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

                                                               
    Milk Patterns
Time Limit: 5000MS   Memory Limit: 65536K
Total Submissions: 13072   Accepted: 5812
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 Ktimes.

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
又是一道瘠薄题 题目大意:求可重叠k次的最长子串长度,同poj1743,只是二分的时候改成如果同一组内元素个数大于等于K return 1
1 #include
2 #include
3 #include
4 #include
5 #include
6 #define maxn 2000005 7 int num[maxn],ws[maxn],wa[maxn],wb[maxn],sa[maxn]; 8 int rank[maxn],h[maxn],n,wv[maxn],K; 9 bool cmp(int *r,int a,int b,int l){10 return r[a]==r[b]&&r[a+l]==r[b+l];11 }12 void da(int *r,int *sa,int n,int m){13 int *t,*x=wa,*y=wb,i,j,p;14 for (i=0;i
=0;i--) sa[--ws[x[i]]]=i;19 for (j=1,p=1;p
=0) y[p++]=sa[i]-j;22 for (i=0;i
=0;i--) sa[--ws[wv[i]]]=y[i];27 for (t=x,x=y,y=t,i=1,p=1,x[sa[0]]=0;i
n) break;42 cnt=1;43 while (i<=n&&h[i]>=x){44 cnt++;45 i++;46 }47 if (cnt>=K) return 1;48 }49 return 0;50 }51 void work(){52 int l=1,r=n,ans;53 while (l<=r){54 int mid=(l+r)/2;55 if (check(mid)) l=mid+1,ans=mid;56 else r=mid-1;57 }58 printf("%d\n",ans);59 }60 int main(){61 while (~scanf("%d%d",&n,&K)){62 for (int i=0;i

 

 

转载于:https://www.cnblogs.com/qzqzgfy/p/5337171.html

你可能感兴趣的文章
探索Javascript异步编程
查看>>
云计算:对计算能力进行贩售的方式
查看>>
《中国人工智能学会通讯》——11.20 多任务学习在交通分析中的应用
查看>>
分析:大数据如何催化电子商务企业
查看>>
H3C吴健:技术与行业理解是我们的核心竞争力
查看>>
CycleBeads:App不仅能避孕,成功率还有95%
查看>>
Android热修复技术总结
查看>>
飞康软件定义平台为Oracle提供全面保护与恢复
查看>>
Java常用算法1——冒泡排序
查看>>
如何在数据中心行业玩转互联网思维?
查看>>
9月6日云栖精选夜读:DMS前后端技术揭秘及最佳实践
查看>>
Oracle Resource Manager和调度任务
查看>>
OpenStack建设企业私有云要解决五大问题
查看>>
美国抢跑5G高频段规划,我国如何应对挑战?
查看>>
路由器桥接怎么设置 其实很简单
查看>>
新型变种病毒,专门攻击安卓机银行App
查看>>
机器学习零基础?手把手教你用TensorFlow搭建图像识别系统(三)| 干货
查看>>
就是这么火!各方大佬谈超融合
查看>>
算算2015年爆出的漏洞总共值多少钱?
查看>>
超融合是快节奏业务环境的必然选择?
查看>>