21: Arithmetic Sequence--HZAU(dp)
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)的更多相关文章
- HZAU 21——Arithmetic Sequence——————【暴力 or dp】
Arithmetic Sequence Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 1810 Solved: 311[Submit][Status] ...
- Arithmetic Sequence(dp)
Arithmetic Sequence Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 51 Solved: 19[Submit][Status][We ...
- hdu 5400 Arithmetic Sequence(模拟)
Problem Description A sequence b1,b2,⋯,bn are called (d1,d2)-arithmetic sequence ≤i≤n) such that ≤j& ...
- [Swift]LeetCode1027. 最长等差数列 | Longest Arithmetic Sequence
Given an array A of integers, return the length of the longest arithmetic subsequence in A. Recall t ...
- (模拟)Arithmetic Sequence -- HDU -- 5400
链接: http://acm.hdu.edu.cn/showproblem.php?pid=5400 Time Limit: 4000/2000 MS (Java/Others) Memory ...
- LeetCode 1027. Longest Arithmetic Sequence
原题链接在这里:https://leetcode.com/problems/longest-arithmetic-sequence/ 题目: Given an array A of integers, ...
- hdu 5400 Arithmetic Sequence
http://acm.hdu.edu.cn/showproblem.php?pid=5400 Arithmetic Sequence Time Limit: 4000/2000 MS (Java/Ot ...
- 华中农业大学第四届程序设计大赛网络同步赛-1020: Arithmetic Sequence,题挺好的,考思路;
1020: Arithmetic Sequence Time Limit: 1 Sec Memory Limit: 128 MB Submit: ->打开链接<- Descriptio ...
- 【leetcode】1027. Longest Arithmetic Sequence
题目如下: Given an array A of integers, return the length of the longest arithmetic subsequence in A. Re ...
- Arithmetic Sequence
Arithmetic Sequence Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
随机推荐
- Apache Httpd + Subversion 搭建HTTP访问的SVN服务器
最近要搭建一个SVN服务器.简单安装之后,本地访问没有问题,但作为服务器肯定是需要HTTP访问.搜索之后,以下是我按照网上的资料搭建的过程,以备后用和参考.(所有软件安装步骤略,没有特殊的,如果没有特 ...
- haproxy+keepalived实现高可用负载均衡
软件负载均衡一般通过两种方式来实现:基于操作系统的软负载实现和基于第三方应用的软负载实现.LVS就是基于Linux操作系统实现的一种软负载,HAProxy就是开源的并且基于第三应用实现的软负载. HA ...
- Swing列表框组件
public class JListTest extends JFrame{ private static final long serialVersionUID=1L; publ ...
- DataSet读取XML
string file = File.ReadAllText("c://123.xml", Encoding.Default); using (DataSet ds = new D ...
- ASP.Net将图片以二进制方式存入数据库,并读取
把图片转换成二进制--把二进制转换成图片 private void button1_Click(object sender, EventArgs e) { string path = this.tex ...
- <a>标签的href和onclick属性
讨论 <a>标签中,href和onclick事件的顺序与冲突问题. 首先明确一点:链接的onclick 事件被先执行,其次是href属性下的动作(页面跳转,或 javascript 伪链接 ...
- PIC32MZ tutorial -- Blinky LED
Today I finish the "Blinky LED" application on PIC32MZ starter kit. This application let L ...
- 关于CacheLookup一个有趣的问题
今天写一个与其他系统进行物料同步的接口,通过COM Business Connector调用Axapta3.0的方法将数据插入到物料表中,中间发生异常,事务回滚,再次调用的时候提示刚刚发生异常的物料已 ...
- ntc 热敏电阻
来自维基百科 http://zh.wikipedia.org/zh/%E7%83%AD%E6%95%8F%E7%94%B5%E9%98%BB 热敏电阻的电阻值是根据温度由公式计算而来的,知道这一点就 ...
- CLR VIA C#委托
1.什么是委托?委托就是一种回调函数的机制,将函数作为一个参数传递给其他对象,当该对象需要的时候调用委托来达到回调函数的目的. 通俗点的说法是:你将一件事情交给别人去做.例如你QQ里的自动回复,为了第 ...