CF633D.Fibonacci-ish

普及+/提高

通过率:0%

时间限制:3.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Yash has recently learnt about the Fibonacci sequence and is very excited about it. He calls a sequence Fibonacci-ish if

  1. the sequence consists of at least two elements
  2. _f_0 and _f_1 are arbitrary
  3. f__n + 2 = f__n + 1 + f__n for all n ≥ 0.

You are given some sequence of integers _a_1, _a_2, ..., a__n. Your task is rearrange elements of this sequence in such a way that its longest possible prefix is Fibonacci-ish sequence.

亚什最近学习了斐波那契数列,对此非常兴奋。他将满足以下条件的序列称为“类斐波那契序列(Fibonacci-ish)”:

  1. 该序列至少包含两个元素;
  2. 首两项 f0f_0 和 f1f_1 可为任意整数;
  3. 对所有 n≥0n \geq 0,满足递推关系 fn+2=fn+1+fnf_{n+2} = f_{n+1} + f_n。

现给你一个整数序列 a1,a2,…,ana_1, a_2, \dots, a_n。你的任务是重排该序列中的元素,使得其最长可能的前缀构成一个类斐波那契序列。

输入格式

The first line of the input contains a single integer n (2 ≤ n ≤ 1000) — the length of the sequence a__i.

The second line contains n integers _a_1, _a_2, ..., a__n (|a__i| ≤ 109).

输入的第一行包含一个整数 nn(2≤n≤10002 \leq n \leq 1000)——序列 aia_i 的长度。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(∣ai∣≤109|a_i| \leq 10^9)。

输出格式

Print the length of the longest possible Fibonacci-ish prefix of the given sequence after rearrangement.

输出给定序列在重排后,其最长可能的类斐波那契(Fibonacci-ish)前缀的长度。

输入输出样例

  • 输入#1

    3
    1 2 -1

    输出#1

    3
  • 输入#2

    5
    28 35 7 14 21

    输出#2

    4

说明/提示

In the first sample, if we rearrange elements of the sequence as  - 1, 2, 1, the whole sequence a__i would be Fibonacci-ish.

In the second sample, the optimal way to rearrange elements is , , , , 28.

在第一个样例中,若将序列元素重新排列为 −1,2,1-1, 2, 1,则整个序列 aia_i 将变为 Fibonacci-ish 序列。

在第二个样例中,重新排列元素的最优方式是 , , , , 28。

输入解题思路,AI测评打分。不知道怎么写?

首页