QOJ.ac

QOJ

时间限制: 3 s 内存限制: 512 MB 总分: 100

#12257. 等差数列

统计

等差数列是指一个数列,其中相邻元素之间的差值是恒定的。例如,数列 $5, 7, 9, 11, 13$ 是一个等差数列(公差为 $2$),但数列 $1, 2, 4, 5$ 不是(相邻元素之间的差分别为 $1, 2, 1$)。

给定一个整数集合 $\{a_1, a_2, \dots, a_n\}$,求其能构成等差数列的最大子集的大小。

如果集合 $A$ 存在一种排列方式使其成为等差数列,则称该集合 $A$ 构成一个等差数列。

输入格式

输入的第一行包含一个整数 $z$,表示测试用例的数量。接下来是各测试用例的描述。

每个测试用例占一行,包含一个整数 $n$ ($1 \le n \le 2000$),随后是 $n$ 个整数 $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^9$)。这些数字互不相同。

输出格式

对于每个测试用例,输出一行,包含在给定集合中找到的最大等差数列的大小。

样例

样例输入 1

2
4 1 2 3 4
6 0 1 2 4 5 6

样例输出 1

4
4

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.