「POJ1743」Musical Theme

2015年4月20日6,1241

Description

A musical melody is represented as a sequence of N (1<=N<=20000)notes that are integers in the range 1..88, each representing a key on the piano. It is unfortunate but true that this representation of melodies ignores the notion of musical timing; but, this programming task is about notes and not timings.
Many composers structure their music around a repeating &qout;theme&qout;, which, being a subsequence of an entire melody, is a sequence of integers in our representation. A subsequence of a melody is a theme if it:

  • is at least five notes long
  • appears (potentially transposed — see below) again somewhere else in the piece of music
  • is disjoint from (i.e., non-overlapping with) at least one of its other appearance(s)

Transposed means that a constant positive or negative value is added to every note value in the theme subsequence.
Given a melody, compute the length (number of notes) of the longest theme.
One second time limit for this problem’s solutions!

Input

The input contains several test cases. The first line of each test case contains the integer N. The following n integers represent the sequence of notes.
The last test case is followed by one zero.

Output

For each test case, the output file should contain a single line with a single integer that represents the length of the longest theme. If there are no themes, output 0.

Sample Input

Sample Output

Hint

Use scanf instead of cin to reduce the read time.

题解

不可重叠最长重复子串

算法1:后缀数组

得出height数组后,二分答案x,将连续的>=x的段分组

如果一组内sa的最大值与最小值的差>=x,则x成立

算法2:后缀自动机

如果我们得出每个结点的right集合

就能得到这些串的出现位置

right集合就是在fail树中子树内结束结点的并集

可以dp出right集合中的最大值/最小值,差值和max取较小值就是到该结点串符合题意的最长长度

代码非常简单  <-hzwer这个傻逼模板打错了还在叽歪

后缀数组

2014.5.8 *1
2014.9.5 *1

后缀自动机 2015.4.10

 

 

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Kings and bears often worry keepers Recent comment authors
  Subscribe  
提醒
Kings and bears often worry keepers
Kings and bears often worry keepers

黄学长,你的后缀数组的代码,判断忘记+1了,然后Wa了