时间限制: 1 s
 空间限制: 128000 KB
 题目等级 : 黄金 Gold
 查看运行结果
 
 
题目描述 Description

给定n(1<=n<=100)个数,从中找出尽可能多的数使得他们能够组成一个等差数列.求最长的等差数列的长度.

输入描述 Input Description

第一行是一个整数n,接下来一行包括了n个数,每个数的绝对值不超过10000000.

输出描述 Output Description

对于每个输入数据,输出你所找出的最长等差数列的长度

样例输入 Sample Input

7

3

8

4

5

6

2

2

样例输出 Sample Output

5

爆搜

  1. #include <algorithm>
  2. #include <cstdio>
  3.  
  4. using namespace std;
  5.  
  6. int n,num[],ans,cnt;
  7.  
  8. void DFS(int pos,int poor)
  9. {
  10. if(pos==n+) return ;
  11. for(int i=pos+;i<=n;i++)
  12. {
  13. if(num[i]-num[pos]==poor)
  14. cnt++,DFS(i,poor);
  15. }
  16. }
  17.  
  18. int main()
  19. {
  20. scanf("%d",&n);
  21. for(int i=;i<=n;i++)
  22. scanf("%d",num+i);
  23. if(n==)
  24. {
  25. puts("");
  26. return ;
  27. }
  28. sort(num+,num+n+);
  29. for(int i=;i<n;i++)
  30. for(int j=i+;j<=n;j++)
  31. {
  32. cnt=;
  33. DFS(i,num[j]-num[i]);
  34. ans=max(ans,cnt);
  35. }
  36. printf("%d",ans);
  37. return ;
  38. }

codevs——T1006 等差数列的更多相关文章

  1. codevs 1006 等差数列

    提交地址:http://codevs.cn/problem/1006/ 1006 等差数列  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold   题目描述 Des ...

  2. codevs——1006 等差数列

    1006 等差数列  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Description 给定n(1<=n< ...

  3. codevs 等差数列

    1006 等差数列  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description 给定n(1<=n<=100) ...

  4. 洛谷P2424/codevs 2606 约数和

    http://codevs.cn/problem/2606/ https://luogu.lohu.info/problem/show?pid=2424 题目背景 Smart最近沉迷于对约数的研究中. ...

  5. code1006 等差数列

    我绞尽脑汁想一个更好的算法,然而不能如愿,只好写一个n^3的了 很简单,就是暴力搜索(还好n<100) 先排序,然后循环i=1ton,j=i+1ton 把a[i]a[j]确定为等差数列开始的两个 ...

  6. 【BZOJ 2124】【CodeVS 1283】等差子序列

    http://www.lydsy.com/JudgeOnline/problem.php?id=2124 http://codevs.cn/problem/1283/ 重点是把判断是否存在3个数组成等 ...

  7. codevs 3289 花匠

    题目:codevs 3289 花匠 链接:http://codevs.cn/problem/3289/ 这道题有点像最长上升序列,但这里不是上升,是最长"波浪"子序列.用动态规划可 ...

  8. codevs 1082 线段树练习 3(区间维护)

    codevs 1082 线段树练习 3  时间限制: 3 s  空间限制: 128000 KB  题目等级 : 大师 Master 题目描述 Description 给你N个数,有两种操作: 1:给区 ...

  9. codevs 1285 二叉查找树STL基本用法

    C++STL库的set就是一个二叉查找树,并且支持结构体. 在写结构体式的二叉查找树时,需要在结构体里面定义操作符 < ,因为需要比较. set经常会用到迭代器,这里说明一下迭代器:可以类似的把 ...

随机推荐

  1. 英语音乐---二、Burning

    英语音乐---二.Burning 一.总结 一句话总结:Burning - Maria Arredondo 玛丽亚·亚瑞唐多(Maria Arredondo),1985年7月6日出生于文内斯拉小镇,挪 ...

  2. layer是什么

    layer是什么 总结 layer就是一个web弹框 简介 layer是一款web弹层组件,致力于服务各个水平段的开发人员. 可以让你想到即可做到的web弹窗 概述 [1]  layer,一个可以让你 ...

  3. 5.不用拷贝的对象可以用ref

    #include <iostream> #include <string> #include <boost/bind.hpp> #include <boost ...

  4. POJ 3145 线段树 分块?+暴力

    思路: 线段树 (分类讨论) 此题数据很水 数据很水 数据很水 但是卡个暴力还是没问题的-- //By SiriusRen #include <cstdio> #include <c ...

  5. springMVC接受前台传值

    今天,用ajax向springMVC的控制器传参数,是一个json对象.({"test":"test","test1":"test ...

  6. js相关禁止

    遇到网页上有精美图片或者精彩文字想保存时,通常大家都是选中目标后按鼠标右键,在弹出菜单中选择“图片另存为”或“复制”来达到我们的目的.但是,目前有许多网页都屏蔽了鼠标右键,那么用js如何实现禁止鼠标右 ...

  7. vue.js技巧小计

    //删除数组索引方法01 del (index) { this.arr.splice(index ,1); } //删除数组索引方法01 del (index) { this.$delete(this ...

  8. Mojo C++ Platform API

    Mojo C++ Platform API This document is a subset of the Mojo documentation. Contents Overview Platfor ...

  9. [Jsoi2010]连通数 bitset + Floyd

    Code: #include<cstdio> #include<algorithm> #include<string> #include<cstring> ...

  10. mysql的关联查询简写

    平常的内连接查询: SELECT * from ab_style as a INNER JOIN ab_url as b on a.style_bold=b.url_id 可支持简写风格: selec ...