A8821 | Almost Arithmetical Progression
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is an almost arithmetical progression, if its elements can be represented as:
- $a_{1}=p$ , where $p$ is some integer;
- $a_{i}=a_{i-1}+(-1)^{i+1}·q$ $(i>1)$ , where $q$ is some integer.
Right now Gena has a piece of paper with sequence $b$ , consisting of $n$ integers. Help Gena, find there the longest subsequence of integers that is an almost arithmetical progression.
Sequence $s_{1},s_{2},...,s_{k}$ is a subsequence of sequence $b_{1},b_{2},...,b_{n}$ , if there is such increasing sequence of indexes $i_{1},i_{2},...,i_{k}$ $(1<=i_{1}<i_{2}<...\ <i_{k}<=n)$ , that $b_{ij}=s_{j}$ . In other words, sequence $s$ can be obtained from $b$ by crossing out some elements.
- $a_{1}=p$ , where $p$ is some integer;
- $a_{i}=a_{i-1}+(-1)^{i+1}·q$ $(i>1)$ , where $q$ is some integer.
Right now Gena has a piece of paper with sequence $b$ , consisting of $n$ integers. Help Gena, find there the longest subsequence of integers that is an almost arithmetical progression.
Sequence $s_{1},s_{2},...,s_{k}$ is a subsequence of sequence $b_{1},b_{2},...,b_{n}$ , if there is such increasing sequence of indexes $i_{1},i_{2},...,i_{k}$ $(1<=i_{1}<i_{2}<...\ <i_{k}<=n)$ , that $b_{ij}=s_{j}$ . In other words, sequence $s$ can be obtained from $b$ by crossing out some elements.
输入格式
The first line contains integer $n$ $(1<=n<=4000)$ . The next line contains $n$ integers $b_{1},b_{2},...,b_{n}$ $(1<=b_{i}<=10^{6})$ .
输出格式
Print a single integer — the length of the required longest subsequence.
输入输出样例
输入 #1
2 3 5
输出 #1
2
输入 #2
4 10 20 10 30
输出 #2
3
In the first test the sequence actually is the suitable subsequence.
In the second test the following subsequence fits: $10,20,10$ .
In the second test the following subsequence fits: $10,20,10$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted