CF813D.Two Melodies
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Alice is a beginner composer and now she is ready to create another masterpiece. And not even the single one but two at the same time!
Alice has a sheet with n notes written on it. She wants to take two such non-empty non-intersecting subsequences that both 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 differs by 1 or are congruent modulo 7.
You should write a program which will calculate maximum sum of lengths of such two non-empty non-intersecting subsequences that both of them form a melody.
爱丽丝是一位初出茅庐的作曲家,现在她准备创作另一部杰作——而且不是一首,而是同时创作两首!
爱丽丝有一张乐谱,上面写有 n 个音符。她希望从中选出两个非空、互不相交的子序列,使得这两个子序列各自都构成一段旋律,且它们的长度之和最大。
子序列是指从原序列中删除若干元素(可为零个)后,保持剩余元素相对顺序不变所得到的序列。
当子序列中每两个相邻音符的差的绝对值为 1,或二者模 7 同余时,该子序列构成一段旋律。
你需要编写一个程序,计算满足上述条件的两个非空、互不相交子序列的最大长度之和。
输入格式
The first line contains one integer number n (2 ≤ n ≤ 5000).
The second line contains n integer numbers _a_1, _a_2, ..., a__n (1 ≤ a__i ≤ 105) — notes written on a sheet.
第一行包含一个整数 $ n ( 2 \leq n \leq 5000 $)。
第二行包含 $ n $ 个整数 $ a_1, a_2, \dots, a_n ( 1 \leq a_i \leq 10^5 $)——写在纸上的音符。
输出格式
Print maximum sum of lengths of such two non-empty non-intersecting subsequences that both of them form a melody.
输出满足以下条件的两个非空、不相交子序列的最大长度之和:这两个子序列各自均构成一段旋律。
输入输出样例
输入#1
4 1 2 4 5
输出#1
4
输入#2
6 62 22 60 61 48 49
输出#2
5
说明/提示
In the first example subsequences [1, 2] and [4, 5] give length 4 in total.
In the second example subsequences [62, 48, 49] and [60, 61] give length 5 in total. If you choose subsequence [62, 61] in the first place then the second melody will have maximum length 2, that gives the result of 4, which is not maximal.
在第一个例子中,子序列 [1, 2] 和 [4, 5] 的总长度为 4。
在第二个例子中,子序列 [62, 48, 49] 和 [60, 61] 的总长度为 5。若首先选择子序列 [62, 61],则第二段旋律的最大长度为 2,结果为 4,这不是最大值。
输入解题思路,AI测评打分。不知道怎么写?