gym 102082B dp


和51nod1055 一样;
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<time.h>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 5005
#define inf 0x7fffffff
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
#define mclr(x,a) memset((x),a,sizeof(x))
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-5
typedef pair<int, int> pii;
#define pi acos(-1.0)
//const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii; inline int rd() {
int x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
int sqr(int x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ int n;
int a[maxn];
int dp[5005][5005];
int main()
{
// ios::sync_with_stdio(0);
n = rd();
for (int i = 1; i <= n; i++) {
a[i] = rd();
}
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++)dp[i][j] = 2;
}
int ans = 2;
for (int i = 1; i <= n - 1; i++) {
int pre = i - 1;
for (int j = i + 1; j <= n; j++) {
while (pre > 0 && a[j] - a[i] > a[i] - a[pre])pre--;
if (!pre)break;
if (pre > 0 && a[j] - a[i] == a[i] - a[pre])
dp[j][i] = max(dp[j][i], dp[i][pre] + 1);
ans = max(ans, dp[j][i]);
}
}
cout << ans << endl;
return 0;
}
gym 102082B dp的更多相关文章
- SEERC 2018 I - Inversion (Gym - 101964I) DP
Gym - 101964I 题意 有一个数组\(p\),如果满足\(i<j,p_i>p_j\),则\(i,j\)之间就有一条边相连,问存在多少个集合满足集合内的元素互不相连,且集合外的元素 ...
- C - Contest Setting Gym - 101982C dp 补题
题目链接:https://vjudge.net/contest/273260#problem/C 学习了一下别人的思路,首先去重,然后离散化. dp数组开二维,每一次更新,状态转移方程,dp[ i ] ...
- Wooden Signs Gym - 101128E (DP)
Problem E: Wooden Signs \[ Time Limit: 1 s \quad Memory Limit: 256 MiB \] 题意 给出一个\(n\),接下来\(n+1\)个数, ...
- Gym 102082B : Arithmetic Progressions
戳这里看题目吧! 题目大意:给你一个长度为n(2<=n<=5000)的序列,没有重复的数字,序列中每个元素满足(0<=numi<=1e9).求一个最长的数列满足差分值相同(除n ...
- Loppinha, the boy who likes sopinha Gym - 101875E (dp,记忆化搜索)
https://vjudge.net/contest/299302#problem/E 题意:给出一个01 0101串,然后能量计算是连续的1就按1, 2, 3的能量加起来.然后给出起始的能量,求最少 ...
- Gym 101334E dp
分析: 这一题给出的遍历的点的序列,不是树的中序遍历,前序遍历,只要遇到一个节点就打印一个节点.关键点就在,这个序列的首字母和尾字母一定要相同,因为最终都会回到根节点,那么每一个子树也一样. 状态: ...
- 2017 United Kingdom and Ireland Programming(Gym - 101606)
题目很水.睡过了迟到了一个小时,到达战场一看,俩队友AC五个了.. 就只贴我补的几个吧. B - Breaking Biscuits Gym - 101606B 旋转卡壳模板题.然后敲错了. 代码是另 ...
- Codeforces Gym 100015F Fighting for Triangles 状压DP
Fighting for Triangles 题目连接: http://codeforces.com/gym/100015/attachments Description Andy and Ralph ...
- Codeforces Gym 100231L Intervals 数位DP
Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description Start with an integer, N0, ...
随机推荐
- Mac os JAVA 开发环境配置简述
本文原文来源:http://blog.csdn.NET/johnstrive/article/details/7791451 1.Mac 自带jdk1.6(本人的机器是这样至于新Mac自带的版本就不清 ...
- web界面上的字体兼容方案
原贴地址:http://www.baidufe.com/item/60cd11d3bfdee5c51369.html 做前端的,对web界面基本都抠的很仔细,尤其精确到1px! 类似边距.宽度.高度等 ...
- saltstack系列(三)——zmq订阅/发布模式
zmq订阅发布模式 server端代码: #coding=utf-8 ''''' 服务端,发布模式 ''' import zmq from random import randrange contex ...
- c# 判断网络地址是否存在
方法一:网络地址存在,有可能可以访问,也有可能不能访问.此方法用来判断地址存在. static bool UrlIsExist(String url) { System.Uri u = null; t ...
- c语言实战 逆序一个三位数
题目:给定一个正的三位整数,比如123,输出321,但如果是700,输出必须是7不能是007 思路是怎么样的呢? 假设这个正三位数是m,它的百分位是c,十分位是b,个位是a,那么就存在下面的等式. m ...
- Linux extundelete命令
一.简介 extundelete的文件恢复工具,支持ext3/ext4双格式分区恢复. 二.安装 yum install -y e2fsprogs* e2fslibs* wget http://nch ...
- 符合mvc思维的分页思想
.Model Student.cs namespace WebApplication14.Models { public class Student { public int Id { get; se ...
- codefirst 最新策略
http://www.yunjuu.com/info/76058.html 在原有数据库中使用 CodeFirst ,除了第一次添加实体后要立即执行一次 Enable-Migrations add-m ...
- Jackson-将对象转为Json字符串
SpringMVC-处理JSON 1.引入jackson依赖 <properties> <jackson.version>1.9.13</jackson.version& ...
- 简单的Session案例 —— 一次性验证码
一次性验证码的主要目的就是为了限制人们利用工具软件来暴力猜测密码,其原理与利用Session防止表单重复提交的原理基本一样,只是将表单标识号变成了验证码的形式,并且要求用户将提示的验证码手工填写进一个 ...