Manthan, Codefest 16-D. Fibonacci-ish
来源:互联网 发布:柯哀分析文 知乎 编辑:程序博客网 时间:2024/05/16 06:52
原题链接
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.
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).
Print the length of the longest possible Fibonacci-ish prefix of the given sequence after rearrangement.
31 2 -1
3
528 35 7 14 21
4
某大牛思路:
#include <bits/stdc++.h>#define maxn 1005#define MOD 1000000007using namespace std;typedef long long ll;map<ll, int> m;int num[maxn];vector<int> v;int main(){//freopen("in.txt", "r", stdin);int n;scanf("%d", &n);for(int i = 0; i < n; i++){ scanf("%d", num+i); m[num[i]]++; } int ans = m[0]; for(int i = 0; i < n; i++) for(int j = 0; j < n; j++){ if(i == j || (!num[i] && !num[j])) continue; v.clear(); v.push_back(num[i]); v.push_back(num[j]); m[num[i]]--; m[num[j]]--; int cnt = 2; ll pre = num[j], k = (ll)num[i] + num[j]; while(m[k]){ cnt++; m[k]--; v.push_back(k); ll d = k; k += pre; pre = d; } ans = max(ans, cnt); for(int i = 0; i < v.size(); i++) m[v[i]]++; } printf("%d\n", ans);return 0;}
- Manthan, Codefest 16 D. Fibonacci-ish
- Manthan, Codefest 16-D. Fibonacci-ish
- Manthan, Codefest 16 D. Fibonacci-ish(暴力、规律)
- Manthan, Codefest 16 633D Fibonacci-ish(脑洞+stl)
- Manthan, Codefest 16 D. Fibonacci-ish(暴力)
- Manthan, Codefest 16 H. Fibonacci-ish II (暴力)
- 【Manthan, Codefest 16D】【暴力+去重or特判】Fibonacci-ish n个数组成最长斐波那契数列的长度
- Manthan Codefest 16 解题报告
- Manthan, Codefest 16 -A Ebony and Ivory
- Manthan, Codefest 16 -B. A Trivial Problem
- Manthan, Codefest 16 -C. Spy Syndrome 2
- Manthan, Codefest 16(A)暴力
- Codeforces 633D Fibonacci-ish(搜索)
- Codeforces 633D Fibonacci-ish 【暴力递归】
- Codeforces 633D Fibonacci-ish(暴力)
- CodeForces - 633D Fibonacci-ish (map&暴力)
- Codeforces 633D Fibonacci-ish 数学+暴力
- CodeForces 633 D.Fibonacci-ish(枚举)
- 程序员Email礼仪
- fck配置,以及上传图片到指定的路径
- 18.js中变量的声明和函数的声明会先被解析
- openfalcon - 再谈数据类型
- QQ游戏百万人同时在线服务器架构实现
- Manthan, Codefest 16-D. Fibonacci-ish
- iOS上架截屏被拒
- java经典面试题解答
- BZOJ3747 POI2015 Kinoman
- node.js的安装
- 编码问题【u和不带u】
- 几种DL的框架,简单介绍
- 数据库设计规范
- iOS 自动化编译&打包