CF818G.Four Melodies
省选/NOI-
通过率:0%
时间限制:5.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Author note: I think some of you might remember the problem "Two Melodies" from Eductational Codeforces Round 22. Now it's time to make it a bit more difficult!
Alice is a composer, and recently she had recorded two tracks that became very popular. Now she has got a lot of fans who are waiting for new tracks.
This time Alice wants to form four melodies for her tracks.
Alice has a sheet with n notes written on it. She wants to take four such non-empty non-intersecting subsequences that all of them form a melody and sum of their lengths is maximal.
Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.
Subsequence forms a melody when each two adjacent notes either differ by 1 or are congruent modulo 7.
You should write a program which will calculate maximum sum of lengths of such four non-empty non-intersecting subsequences that all of them form a melody.
作者注:我想你们中有些人可能还记得 Educational Codeforces Round 22 中的题目“Two Melodies”。现在是时候让它变得更难一点了!
爱丽丝是一位作曲家,最近她录制了两首广受欢迎的乐曲。如今,她拥有了大量期待新作品的粉丝。
这一次,爱丽丝希望为她的乐曲创作四段旋律。
爱丽丝有一张乐谱,上面写有 n 个音符。她希望从中选出四个非空、互不相交的子序列,使得这四个子序列各自都构成一段旋律,并且它们的长度之和最大。
子序列是指通过从原序列中删除若干元素(不改变剩余元素的相对顺序)而得到的序列。
当子序列中任意两个相邻音符之间的差值为 1,或二者模 7 同余时,该子序列构成一段旋律。
你需要编写一个程序,计算满足上述条件的四个非空、互不相交子序列的最大长度总和。
输入格式
The first line contains one integer number n (4 ≤ n ≤ 3000).
The second line contains n integer numbers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 105) — notes written on a sheet.
第一行包含一个整数 $ n ( 4 \leq n \leq 3000 $)。
第二行包含 $ n $ 个整数 $ a_1, a_2, \ldots, a_n ( 1 \leq a_i \leq 10^5 $)——写在纸上的音符。
输出格式
Print maximum sum of lengths of such four non-empty non-intersecting subsequences that all of them form a melody.
输出满足以下条件的四个非空、互不相交的子序列的最大长度之和,且这四个子序列各自均构成一段旋律。
输入输出样例
输入#1
5 1 3 5 7 9
输出#1
4
输入#2
5 1 3 5 7 2
输出#2
5
说明/提示
In the first example it is possible to compose 4 melodies by choosing any 4 notes (and each melody will consist of only one note).
In the second example it is possible to compose one melody with 2 notes — {1, 2}. Remaining notes are used in other three melodies (one note per each melody).
在第一个例子中,可以通过选择任意 4 个音符来组成 4 段旋律(每段旋律仅包含一个音符)。
在第二个例子中,可以组成一段包含 2 个音符的旋律——{1, 2}。其余音符则用于另外三段旋律(每段旋律各使用一个音符)。
输入解题思路,AI测评打分。不知道怎么写?