#P14894. [ICPC 2018 Yokohama R] Arithmetic Progressions

    ID: 16711 远端评测题 5000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>动态规划 DP2018ICPC双指针 two-pointer哈希表横浜

[ICPC 2018 Yokohama R] Arithmetic Progressions

题目描述

An arithmetic progression is a sequence of numbers a1a_1, a2a_2, \ldots, aka_k where the difference of consecutive members ai+1aia_{i+1} - a_i is a constant (1ik11 \leq i \leq k-1). For example, the sequence 55, 88, 1111, 1414, 1717 is an arithmetic progression of length 55 with the common difference 33.

In this problem, you are requested to find the longest arithmetic progression which can be formed selecting some numbers from a given set of numbers. For example, if the given set of numbers is {0,1,3,5,6,9}\{0, 1, 3, 5, 6, 9\}, you can form arithmetic progressions such as 00, 33, 66, 99 with the common difference 33, or 99, 55, 11 with the common difference 4-4. In this case, the progressions 00, 33, 66, 99 and 99, 66, 33, 00 are the longest.

输入格式

The input consists of a single test case of the following format.

$$\begin{aligned} &n \\ &v_1 & v_2 & \cdots & v_n\\ \end{aligned}$$

nn is the number of elements of the set, which is an integer satisfying 2n50002 \leq n \leq 5000. Each viv_i (1in1 \leq i \leq n) is an element of the set, which is an integer satisfying 0vi1090 \leq v_i \leq 10^9. viv_i's are all different, i.e., vivjv_i \neq v_j if iji \neq j.

输出格式

Output the length of the longest arithmetic progressions which can be formed selecting some numbers from the given set of numbers.

6
0 1 3 5 6 9
4
7
1 4 7 3 2 6 5
7
5
1 2 4 8 16

2