Description

An arithmetic series consists of a sequence of terms such that each term minus its immediate predecessor gives the same result. For example, the sequence 3, 7, 11, 15 is the terms of the arithmetic series 3+7+11+15; each term minus its predecessor equals 4. (Of course there is no requirement on the first term since it has no predecessor.)

Given a collection of integers, we want to find the longest arithmetic series that can be formed by choosing a sub-collection (possibly the entire collection).

Input

There are multiple cases, and each case contains 2 lines: the first line contains the count of integers (between 2 and 1000 inclusive), the following line contains all the integers (between -1,000,000,000 and 1,000,000,000 inclusive) separated by one or more spaces.

Output

Print a single number for each case in a single line.

Sample Input

7
3 8 4 5 6 2 2
4
-1 -5 1 3
4
-10 -20 -10 -10

Sample Output

5
3
3

Source

ZOJ Monthly, 2005.9

看了别人的解题报告说是DP+二分。试着写了一个后来发现与实际的结果相差2,不管三七二十一直接在原来的结果上加2。

竟然过了~o(╯□╰)o

cjx就在想这是为什么呢?后来发现因为我是从第三个数开始处理的,每个运算的结果都会少个2。

 #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#define MAXN 1001
using namespace std; int n,cnt;
int d[MAXN];
int a[MAXN];
int dp[MAXN][MAXN]; int find(int l, int r, int v){
while(l<=r){
int m=(l+r)/;
if(v==a[m])return m;
else if(v<a[m]){
r=m-;
}else if(v>a[m]){
l=m+;
}
}
return -;
} int main()
{
int ans,count;
int temp;
while( scanf("%d",&n)!=EOF ){
for(int i=; i<n; i++){
scanf("%d",&d[i]);
}
sort(d,d+n);
cnt=;
count=;
ans=;
temp=-;
for(int i=; i<n; i++){
if(d[i]!=temp){
a[cnt++]=d[i];
if(count>ans)
ans=count;
count=;
}else{
count++;
}
}
if(count>ans){
ans=count;
}
memset(dp,,sizeof(dp));
for(int i=; i<cnt; i++){
for(int j=i+; j<cnt; j++){
int v=a[j]+a[j]-a[i];
int k=-;
k=find(j+,cnt-,v);
if(k!=-){
dp[j][k]=dp[i][j]+;
if(dp[j][k]>=ans){
ans=dp[j][k];
}
}
}
}
printf("%d\n",ans+);
}
return ;
}

TOJ 2926 Series的更多相关文章

  1. 利用Python进行数据分析(8) pandas基础: Series和DataFrame的基本操作

    一.reindex() 方法:重新索引 针对 Series   重新索引指的是根据index参数重新进行排序. 如果传入的索引值在数据里不存在,则不会报错,而是添加缺失值的新行. 不想用缺失值,可以用 ...

  2. 利用Python进行数据分析(7) pandas基础: Series和DataFrame的简单介绍

    一.pandas 是什么 pandas 是基于 NumPy 的一个 Python 数据分析包,主要目的是为了数据分析.它提供了大量高级的数据结构和对数据处理的方法. pandas 有两个主要的数据结构 ...

  3. 数据分析(8):Series介绍

    Series Series由一组数据及索引组成 索引 采用默认索引 data = pd.Series([4, 3, 2, 1]) 自定义索引 data = pd.Series([4, 3, 2, 1] ...

  4. POJ 3233Matrix Power Series

    妈妈呀....这简直是目前死得最惨的一次. 贴题目: http://poj.org/problem?id=3233 Matrix Power Series Time Limit: 3000MS Mem ...

  5. highchart 添加新的series

    code: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" c ...

  6. C# Chart控件,chart、Series、ChartArea曲线图绘制的重要属性

    http://blog.sina.com.cn/s/blog_621e24e20101cp64.html 为避免耽误不喜欢这种曲线图效果的亲们的时间,先看一下小DEMO效果图: 先简单说一下,从图中可 ...

  7. pandas 学习(1): pandas 数据结构之Series

    1. Series Series 是一个类数组的数据结构,同时带有标签(lable)或者说索引(index). 1.1 下边生成一个最简单的Series对象,因为没有给Series指定索引,所以此时会 ...

  8. TOJ 2776 CD Making

    TOJ 2776题目链接http://acm.tju.edu.cn/toj/showp2776.html 这题其实就是考虑的周全性...  贡献了好几次WA, 后来想了半天才知道哪里有遗漏.最大的问题 ...

  9. TOJ 1191. The Worm Turns

    191.   The Worm Turns Time Limit: 1.0 Seconds   Memory Limit: 65536K Total Runs: 5465   Accepted Run ...

随机推荐

  1. HTML5移动Web开发实战 PDF扫描版​

    <HTML5移动Web开发实战>提供了应对这一挑战的解决方案.通过阅读本书,你将了解如何有效地利用最新的HTML5的那些针对移动网站的功能,横跨多个移动平台.全书共分10章,从移动Web. ...

  2. Android ActionBar仿微信界面

    ActionBar仿微信界面 1.学习了别人的两篇关于ActionBar博客,在结合别人的文章来仿造一下微信的界面: 思路如下:1).利用ActionBar生成界面的头部,在用ActionBar的Ac ...

  3. jQuery之方法绑定(事件注册)代码小结

    1.最直接的模式,直接将一个function对象传入方法函数,如下面的click(),好处坏处一看便知 $("#btnComfirmChooseCompany").click(fu ...

  4. const限定符、constexpr和常量表达式------c++ primer

    编译器将在编译过程中把用到const变量的地方都替换成对应的值,为了执行这种替换,编译器必须知道变量的初始值.如果程序包含多个文件,则那个用了const对象的文件都必须能访问到它的初始值才行.要做到这 ...

  5. Jmeter的主要元件及元件的执行顺序

    一.JMeter的主要元素 1.Test Pan(测试计划) Jmeter中的测试计划包括一个或者一组的测试用例,一个Thread Group可以认为是一个测试用例,一个测试计划中可以包括多个Thre ...

  6. Spring之BeanFactory与ApplicationConText

    :BeanFactory基本的工厂解析,管理,实例化所有容器内的bean的接口,spring中所有解析配置文件的类都直接或者间接实现该接口ApplicationContext接口implements ...

  7. uoj#344. 【清华集训2017】我的生命已如风中残烛(计算几何)

    题面 传送门 题解 orzxyx 首先我们发现,一个点如果被到达大于一次,那么这个点肯定在一个环上.所以在不考虑环的情况下每个点只会被到达一次,那么我们就可以直接暴力了 简单来说,我们对每个点\(i\ ...

  8. HDU - 5996 树上博弈 BestCoder Round #90

    就是阶梯NIM博弈,那么看层数是不是奇数的异或就行了: #include<iostream> #include<cstdio> #include<algorithm> ...

  9. 洛谷 P1217 [USACO1.5]回文质数 Prime Palindrome

    嗯... 这道题对于蒟蒻的我来说实在是TQL... 先看一下题:(题目链接:https://www.luogu.org/problemnew/show/P1217) 然后说一下我的做题过程吧: 一看到 ...

  10. 20165224 陆艺杰 Exp3 免杀原理与实践

    杀软是如何检测出恶意代码的? 识别代码特征码 监测像后门的行为 (2)免杀是做什么? 让后面程序不被安全软件发现 (3)免杀的基本方法有哪些? 多方式编码 半手工shellcode编程 完全自己写没有 ...