CF255C.Almost Arithmetical Progression
普及/提高-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as:
- _a_1 = p, where p is some integer;
- a__i = a__i - 1 + ( - 1)i + 1·q (i > 1), where q is some integer.
Right now Gena has a piece of paper with sequence b, consisting of n integers. Help Gena, find there the longest subsequence of integers that is an almost arithmetical progression.
Sequence _s_1, _s_2, ..., s__k is a subsequence of sequence _b_1, _b_2, ..., b__n, if there is such increasing sequence of indexes _i_1, _i_2, ..., i__k (1 ≤ _i_1 < _i_2 < ... < i__k ≤ n), that b__i__j = s__j. In other words, sequence s can be obtained from b by crossing out some elements.
杰纳喜欢数字序列。最近,他发现了一种新型序列,并将其称为“准等差数列”。若一个序列的元素可表示为:
- a1=p,其中 p 为某个整数;
- ai=ai−1+(−1)i+1⋅q(当 i>1 时),其中 q 为某个整数,
则该序列为一个准等差数列。
目前,杰纳有一张写有长度为 n 的整数序列 b 的纸。请帮助杰纳找出其中最长的子序列,使其构成一个准等差数列。
序列 s1, s2, …, sk 是序列 b1, b2, …, bn 的一个子序列,当且仅当存在一个严格递增的下标序列 i1, i2, …, ik(满足 1≤i1<i2<⋯<ik≤n),使得对所有 j=1,2,…,k 都有 bij=sj。换言之,序列 s 可通过对序列 b 删除若干元素而得到。
输入格式
The first line contains integer n (1 ≤ n ≤ 4000). The next line contains n integers _b_1, _b_2, ..., b__n (1 ≤ b__i ≤ 106).
第一行包含一个整数 n(1 ≤ n ≤ 4000)。下一行包含 n 个整数 b1, b2, ..., bn(1 ≤ bi ≤ 106)。
输出格式
Print a single integer — the length of the required longest subsequence.
输出一个整数——所求最长子序列的长度。
输入输出样例
输入#1
2 3 5
输出#1
2
输入#2
4 10 20 10 30
输出#2
3
说明/提示
In the first test the sequence actually is the suitable subsequence.
In the second test the following subsequence fits: 10, 20, 10.
在第一个测试用例中,该序列本身就是合适的子序列。
在第二个测试用例中,以下子序列满足条件:10, 20, 10。
输入解题思路,AI测评打分。不知道怎么写?