Pro.ID10196 TitleMusical Themes Title链接http://10.20.2.8/oj/exercise/problem?problem_id=10196 AC8 Submit37 Ratio21.62% 时间&空间限制描述A musical melody is represented as a sequence of N (1 ≤ N ≤ 5000) 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 "theme", 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:
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! 输入Multiple test cases. For each case, the first line has an integer N. Each subsequent line (except potentially the last) contains 20 integers representing the sequence of notes. The last line contains the remainder of the notes, potentially fewer than 20. 输出Description A musical melody is represented as a sequence of N (1 ≤ N ≤ 5000) 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 "theme", 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:
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 Multiple test cases. For each case, the first line has an integer N. Each subsequent line (except potentially the last) contains 20 integers representing the sequence of notes. The last line contains the remainder of the notes, potentially fewer than 20. Output For each case, output a single line with a single integer that represents the length of the longest theme. If there are no themes, output 0. Sample Input 30 Sample Output 5 Hint The five-long theme is the last five notes of the first line and the first five notes of the second. Source 样例输入30 样例输出5 提示The five-long theme is the last five notes of the first line and the first five notes of the second. |