当前位置: 首页 > article >正文

题解:CF633D Fibonacci-ish

原题

题目描述

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.

输入格式

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}|<=10^{9} $ ).

输出格式

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

输入输出样例 #1

输入 #1

3
1 2 -1

输出 #1

3

输入输出样例 #2

输入 #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 $ .

思路

先看数据范围 2 ≤ n ≤ 1000 2≤n≤1000 2n1000,直接暴力加剪枝就能过。

我们首先用 map 建一个桶,统计每个数出现的次数,然后用双重 for 循环枚举前两个数。

然后,我们再来看如何剪枝:

  • 如果 2

http://www.kler.cn/a/579632.html

相关文章:

  • Linux 进程管理 -- 进程的替换 (补进程创建)
  • MySQL环境安装详细教程(Windows/macOS/Linux)
  • 聚焦两会:科技与发展并进,赛逸展2025成创新新舞台
  • CI/CD—Jenkins cron定时任务表达式
  • 【微知】qemu如何配置ctrl+c不退出qemu系统?(-chardev stdio,id=char0,signal=off)
  • Go泛型学习笔记
  • C++二叉搜索树代码
  • 旋转验证码截图识别
  • ⭐LeetCode(数学分类) 48. 旋转图像——优美的数学法转圈(原地修改)⭐
  • Easysearch 使用 AWS S3 进行快照备份与还原:完整指南及常见错误排查
  • 蓝桥杯[每日两题] 真题:好数 神奇闹钟 (java版)
  • 【微知】如何根据内核模块ko查看所依赖其他哪些模块?(modinfo rdma_ucm |grep depends)
  • 【Java学习】包装类
  • 基于策略模式的智能提示语生成器设计与实现——以Tkinter GUI开发为例
  • 一文了解汽车图像传感器
  • 1-002:MySQL InnoDB引擎中的聚簇索引和非聚簇索引有什么区别?
  • 逐梦DBA:Linux下MySQL字符集的处理
  • OkHttp 之任务调度模块源码分析
  • 为php添加额外的功能模块
  • 论文阅读笔记——OpenVLA: An Open-Source Vision-Language-Action Model