http://acm.hzau.edu.cn/problem.php?id=21

题目大意: 给你一个序列问在数字最多的等比数列

分析:  刚开始看到题就知道是一个dp但是我dp实在是渣到不行

后来发现用二维dp  第二位保存i到j的差

#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <stack>
#include <algorithm>
using namespace std;
#define N 2050
#define memset(a,b) memset(a,b,sizeof(a)) int dp[N][N]; int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<=;i++)
{
for(int j=;j<=;j++)
{
dp[i][j]=;
}
}
int a[N];
memset(a,);
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
int Max=;
for(int i=;i<n;i++)
{
for(int j=;j<i;j++)
{
int d=a[i]-a[j];
dp[i][d]=dp[j][d]+;
Max=max(Max,dp[i][d]);
}
}
printf("%d\n",Max);
}
return ;
}

21: Arithmetic Sequence--HZAU(dp)的更多相关文章

  1. HZAU 21——Arithmetic Sequence——————【暴力 or dp】

    Arithmetic Sequence Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 1810  Solved: 311[Submit][Status] ...

  2. Arithmetic Sequence(dp)

    Arithmetic Sequence Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 51  Solved: 19[Submit][Status][We ...

  3. hdu 5400 Arithmetic Sequence(模拟)

    Problem Description A sequence b1,b2,⋯,bn are called (d1,d2)-arithmetic sequence ≤i≤n) such that ≤j& ...

  4. [Swift]LeetCode1027. 最长等差数列 | Longest Arithmetic Sequence

    Given an array A of integers, return the length of the longest arithmetic subsequence in A. Recall t ...

  5. (模拟)Arithmetic Sequence -- HDU -- 5400

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=5400 Time Limit: 4000/2000 MS (Java/Others)    Memory ...

  6. LeetCode 1027. Longest Arithmetic Sequence

    原题链接在这里:https://leetcode.com/problems/longest-arithmetic-sequence/ 题目: Given an array A of integers, ...

  7. hdu 5400 Arithmetic Sequence

    http://acm.hdu.edu.cn/showproblem.php?pid=5400 Arithmetic Sequence Time Limit: 4000/2000 MS (Java/Ot ...

  8. 华中农业大学第四届程序设计大赛网络同步赛-1020: Arithmetic Sequence,题挺好的,考思路;

    1020: Arithmetic Sequence Time Limit: 1 Sec  Memory Limit: 128 MB Submit:  ->打开链接<- Descriptio ...

  9. 【leetcode】1027. Longest Arithmetic Sequence

    题目如下: Given an array A of integers, return the length of the longest arithmetic subsequence in A. Re ...

  10. Arithmetic Sequence

    Arithmetic Sequence Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

随机推荐

  1. haproxy+keepalived实现高可用负载均衡

    软件负载均衡一般通过两种方式来实现:基于操作系统的软负载实现和基于第三方应用的软负载实现.LVS就是基于Linux操作系统实现的一种软负载,HAProxy就是开源的并且基于第三应用实现的软负载. HA ...

  2. EditText 自动格式化电话电话号码

    需要格式化的格式为:xxx xxxx xxxx 有两种方式:1.为监听当前输入的长度,当长度为第四位,九位的时候,在原内容上追加空格.(from stackOverFlow)2.每次输入后,格式化当前 ...

  3. #ifdef #ifndef使用

    #ifdef THREAD_ON while (TRUE) #endif 如上没定义THREAD_ON时,是不会跑到while中去的 如上没定义THREAD_ON时,是会跑到else中去的 #ifnd ...

  4. (转载)SQL Server 2005 如何启用xp_cmdshell组件

    原文地址:http://www.cnblogs.com/atree/p/SQL_SERVER_xp_cmdshell.html [错误描述]: SQL Server阻止了对组件‘xp_cmdshell ...

  5. ubuntu 12.04 设置代理

    一. Ubuntu 12.04 apt-get 代理设置 由于公司通过代理上网,firefox的代理设置很容易就搞定了,但是通过apt-get安装软件还是不行,于是,查阅了很多资料,最多的方法就是网上 ...

  6. Angularjs-Dirty Checking

    Angularjs实现了数据双向绑定,就像下面这样: <!doctype html> <htnl ng-app> <head> <script src=&qu ...

  7. Tomcat从内存、并发、缓存方面优化方法

    Tomcat有很多方面,从内存.并发.缓存四个方面介绍优化方法.   一.Tomcat内存优化 Tomcat内存优化主要是对 tomcat 启动参数优化,我们可以在 tomcat 的启动脚本 cata ...

  8. skiplist

    §1 Skip List 介绍 Skip List是一种随机化的数据结构,基于并联的链表,其效率可比拟于二叉查找树(对于大多数操作需要O(log n)平均时间).基本上, 跳跃列表是对有序的链表增加上 ...

  9. sql条件中比较性能优化

    第一个比第二个性能高. 查询语句意义: 如果codelist中tablecode配置为0时, t.Table_Code = 'SV_RETURN_BILL'不生效. 如果codelist中tablec ...

  10. Linux下/boot目录

    /boot目录存放的是开机所需的文件----内核,开机菜单,及所需配置文件等: (1)系统Kernel的配置文件: (2)启动管理程序GRUB的目录,里面放的都是GRUB在启动时所需要的画面.配置及各 ...