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. SQL%NOTFOUND

    异常相关: 源地址:https://zhidao.baidu.com/question/215737667.html EXCEPTIONwhen others thenrollback;dbms_ou ...

  2. mysql 修改字段类型

    1.更改Float字段类型to Decimal ALTER TABLE 表名 MODIFY 字段名 decimal(10,2) not null default '0': 如: ALTER TABLE ...

  3. Java操作SFTP

    import java.util.Properties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.jcr ...

  4. iOS开发官方文档汇总

    程序员的学习过程是无止境的,程序员学习的途径是多样的.可以从视频教程中领悟,也可以从他人的代码中 理解.但当我们专注于某一个平台在开发的时候,对于某个API使用或者功能实现有疑问,通常简单的测试可以让 ...

  5. auto,register,static分析

    1.关键字auto auto是C语言中局部变量的默认类型,指明声明的变量在程序的栈上分配空间. 2.关键字static 指明变量的“静态”属性,局部变量存储在静态存储区: 文件作用标示符,只能在声明的 ...

  6. UBUNTU 13.04 install Grive

    sudo apt-get install software-properties-common sudo apt-get install python-software-properties sudo ...

  7. 5.Firedac错误信息

    主要错误信息属性: 1.EFDDBEngineException Errors -- TFDDBError对象集合. ErrorCount --错误的记录数 Kind -- DBMS的错误集合. Me ...

  8. web form 基础知识初整理

    WebForm的基础知识1.(IIS7的标准首页iisstart.htm)ASP.NET 是.NET开发网站应用程序的技术总称 ,有两种方法,1.webform :比如淘宝 2.MVC B/S 一种网 ...

  9. c#基础-oop(面向对象理解)

    OOP-面向对象 封装,继承多态 一个桌子,用面向对象来描述一下它这个桌子项目 定义桌子类 对象:桌子 桌子的属性:名字,材质,体积 桌子的方法;放东西(方法) 现在桌子要放书,放花瓶,放文件(这里就 ...

  10. Android 中的 Service 全面总结(转载)

    转载地址:http://www.cnblogs.com/newcj/archive/2011/05/30/2061370.html 感谢作者 Android 中的 Service 全面总结 1.Ser ...