CodeForces - 633D Fibonacci-ish (map&暴力)
2016-03-12 16:07
387 查看
CodeForces - 633D Fibonacci-ish
Description Yash has recently learnt about the Fibonacci sequence and is very excited about it. He calls a sequence Fibonacci-ish if the sequence consists of at least two elements f0 and f1 are arbitrary fn + 2 = fn + 1 + fn for all n ≥ 0. You are given some sequence of integers a1, a2, ..., an. Your task is rearrange elements of this sequence in such a way that its longest possible prefix is Fibonacci-ish sequence. Input The first line of the input contains a single integer n (2 ≤ n ≤ 1000) — the length of the sequence ai. The second line contains n integers a1, a2, ..., an (|ai| ≤ 109). Output Print the length of the longest possible Fibonacci-ish prefix of the given sequence after rearrangement. Sample Input Input 3 1 2 -1 Output 3 Input 5 28 35 7 14 21 Output 4 Hint In the first sample, if we rearrange elements of the sequence as - 1, 2, 1, the whole sequence ai would be Fibonacci-ish. In the second sample, the optimal way to rearrange elements is , , , , 28. Source Manthan, Codefest 16 //上次就遇见一个题,考试完听大神说是用map做的,这次又是一个map,看来是时候学一下map了。 这个是看大神的代码写的,还在理解中。。。 #include<stdio.h> |
相关文章推荐
- extjs6 入门 sencha cmd 新建项目
- 单元测试
- event 事件 onkeydown event.keyCode只能输入数字的文本框
- 将博客搬至CSDN
- 13 完整实现三子棋小游戏-DirectX游戏开发初级教程
- 第二周学习进度
- lua-队列
- The 6th Zhejiang Provincial Collegiate Programming Contest
- 第二次上机实践项目-项目3-输出星号图
- 【转载】Contiki 的protothreads
- 第二周学习进度
- Linux--01入门
- VTK 7.0 安装中内存读取冲突 no override found for “.." 解决记录
- react.js-06-propTypes类型校验
- 剑指offer 调整数组顺序使奇数位于偶数前面
- Hadoop-异常“could only be replicated to 0 nodes, instead of 1”
- android TIF HAL层代码分析
- Android双向滑动冲突解决方案
- 【动态规划】[USACO2016 金组]Circular Barn Revisited
- MySQL 中BLOB/TEXT column can't have a default value query问题