TOJ 2926 Series
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
看了别人的解题报告说是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的更多相关文章
- 利用Python进行数据分析(8) pandas基础: Series和DataFrame的基本操作
一.reindex() 方法:重新索引 针对 Series 重新索引指的是根据index参数重新进行排序. 如果传入的索引值在数据里不存在,则不会报错,而是添加缺失值的新行. 不想用缺失值,可以用 ...
- 利用Python进行数据分析(7) pandas基础: Series和DataFrame的简单介绍
一.pandas 是什么 pandas 是基于 NumPy 的一个 Python 数据分析包,主要目的是为了数据分析.它提供了大量高级的数据结构和对数据处理的方法. pandas 有两个主要的数据结构 ...
- 数据分析(8):Series介绍
Series Series由一组数据及索引组成 索引 采用默认索引 data = pd.Series([4, 3, 2, 1]) 自定义索引 data = pd.Series([4, 3, 2, 1] ...
- POJ 3233Matrix Power Series
妈妈呀....这简直是目前死得最惨的一次. 贴题目: http://poj.org/problem?id=3233 Matrix Power Series Time Limit: 3000MS Mem ...
- highchart 添加新的series
code: <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" c ...
- C# Chart控件,chart、Series、ChartArea曲线图绘制的重要属性
http://blog.sina.com.cn/s/blog_621e24e20101cp64.html 为避免耽误不喜欢这种曲线图效果的亲们的时间,先看一下小DEMO效果图: 先简单说一下,从图中可 ...
- pandas 学习(1): pandas 数据结构之Series
1. Series Series 是一个类数组的数据结构,同时带有标签(lable)或者说索引(index). 1.1 下边生成一个最简单的Series对象,因为没有给Series指定索引,所以此时会 ...
- TOJ 2776 CD Making
TOJ 2776题目链接http://acm.tju.edu.cn/toj/showp2776.html 这题其实就是考虑的周全性... 贡献了好几次WA, 后来想了半天才知道哪里有遗漏.最大的问题 ...
- TOJ 1191. The Worm Turns
191. The Worm Turns Time Limit: 1.0 Seconds Memory Limit: 65536K Total Runs: 5465 Accepted Run ...
随机推荐
- C# - dynamic 特性
dynamic是FrameWork4.0的新特性.dynamic的出现让C#具有了弱语言类型的特性.编译器在编译的时候不再对类型进行检查,编译期默认dynamic对象支持你想要的任何特性. 比如,即使 ...
- Boost 安装详解
一 Linux(redhat)篇 1.1 获取boost库 解压tar -zxvf boost_1.48.0.tar.gz 进入解压目录cd boost_1_48_0 1.2 编译安装 使用下面的命令 ...
- 随便写个bat存档
@echo off @COLOR @echo ------------切换Hosts环境--------------- :Again @set /p choice="切换模式:A:应用环境, ...
- [.net 多线程]volatile 摘录
一.volatile 介绍 volatile 关键字指示一个字段可以由多个同时执行的线程修改. 声明为 volatile 的字段不受编译器优化(假定由单个线程访问)的限制. 这样可以确保该字段在任何时 ...
- mysql 新建数据库与表
- 关于“java.lang.OutOfMemoryError : unable to create new native Thread”的报错问题
好吧 我发誓这是postgresql的Mirroring Controller的RT测试的最后一个坑了. 在这个RT测试的最后,要求测试Mirroring Controller功能在长时间运行下的稳定 ...
- Udp -内部缓冲区
1.每个socket关联了两个缓冲区,一个用于发送,一个用于接收. 2. 3.发送:(1)sendto()把数据放在sendbuf(缓冲区),通知os来取 (2)os在适当的时候过来取数据,并发到网络 ...
- 如何把win10系统迁移到SSD固态硬盘
https://jingyan.baidu.com/article/5d368d1ec59ac43f60c05733.html 我之前将两个盘都已经固定在笔记本内,迁移完之后无论怎么改还是从原来的机械 ...
- 斐讯 N1 刷 Armbian 5.64
前言 N1 天天链是斐讯出的一款挖矿产品,虽然已经翻车,但是本身硬件配置还是很不错的,晶晨 S905D 主控,蓝牙 4.1,双频 WiFi,2G + 8G,USB2.0,HDMI.而一个只要不到 80 ...
- requests 模块使用代理
正向代理与反向代理的区别 反向代理: 服务器端知道代理的存在,反向代理是为了保护服务器或负责负载均衡 但是客户端不知道代理的存在的 正向代理: 客户端知道代理的存在,正向代理是为保护客户端,防止追究责 ...