和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的更多相关文章

  1. SEERC 2018 I - Inversion (Gym - 101964I) DP

    Gym - 101964I 题意 有一个数组\(p\),如果满足\(i<j,p_i>p_j\),则\(i,j\)之间就有一条边相连,问存在多少个集合满足集合内的元素互不相连,且集合外的元素 ...

  2. C - Contest Setting Gym - 101982C dp 补题

    题目链接:https://vjudge.net/contest/273260#problem/C 学习了一下别人的思路,首先去重,然后离散化. dp数组开二维,每一次更新,状态转移方程,dp[ i ] ...

  3. Wooden Signs Gym - 101128E (DP)

    Problem E: Wooden Signs \[ Time Limit: 1 s \quad Memory Limit: 256 MiB \] 题意 给出一个\(n\),接下来\(n+1\)个数, ...

  4. Gym 102082B : Arithmetic Progressions

    戳这里看题目吧! 题目大意:给你一个长度为n(2<=n<=5000)的序列,没有重复的数字,序列中每个元素满足(0<=numi<=1e9).求一个最长的数列满足差分值相同(除n ...

  5. Loppinha, the boy who likes sopinha Gym - 101875E (dp,记忆化搜索)

    https://vjudge.net/contest/299302#problem/E 题意:给出一个01 0101串,然后能量计算是连续的1就按1, 2, 3的能量加起来.然后给出起始的能量,求最少 ...

  6. Gym 101334E dp

    分析: 这一题给出的遍历的点的序列,不是树的中序遍历,前序遍历,只要遇到一个节点就打印一个节点.关键点就在,这个序列的首字母和尾字母一定要相同,因为最终都会回到根节点,那么每一个子树也一样. 状态: ...

  7. 2017 United Kingdom and Ireland Programming(Gym - 101606)

    题目很水.睡过了迟到了一个小时,到达战场一看,俩队友AC五个了.. 就只贴我补的几个吧. B - Breaking Biscuits Gym - 101606B 旋转卡壳模板题.然后敲错了. 代码是另 ...

  8. Codeforces Gym 100015F Fighting for Triangles 状压DP

    Fighting for Triangles 题目连接: http://codeforces.com/gym/100015/attachments Description Andy and Ralph ...

  9. Codeforces Gym 100231L Intervals 数位DP

    Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description Start with an integer, N0, ...

随机推荐

  1. kibana.yml(中文配置详解)

    # Kibana is served by a back end server. This controls which port to use. # server.port: 5601 # The ...

  2. Gym 101606 F-Flipping Coins(概率dp)

    参考博客:http://www.cnblogs.com/kang000/p/8571071.html  (这篇博客写的真的走心,ORZ) 题意有n个硬币排成一排,开始的时候所有的硬币都是正面朝下,你必 ...

  3. 598. Range Addition II 矩阵的范围叠加

    [抄题]: Given an m * n matrix M initialized with all 0's and several update operations. Operations are ...

  4. mybatis 框架 的应用之四(一对一 与 一对多)

    lf-driver=com.mysql.jdbc.Driver lf-url=jdbc:mysql://localhost:3306/test?allowMultiQueries=true&u ...

  5. 如何从Win7上卸载Sql 2008 R2 Express,再重装

    这两天,因工作需要,需要在一台新的机器上,Win7 64位英文操作系统上,安装Sql Server 2008 R2 Express,安装的过程中出现些问题,在查找问题的过程中,考虑重装 Sql Ser ...

  6. hook NtQueryDirectoryFile实现文件隐藏

    一.NtQueryDirectoryFile函数功能(NT系列函数) NtQueryDirectoryFile函数:在一个给定的文件句柄,该函数返回该文件句柄指定目录下的不同文件的各种信息. 根据传入 ...

  7. Luogu 4951 [USACO 2001 OPEN]地震

    水个博客玩. $01$分数规划. 题目要求$\frac{F - \sum_{i = 1}^{n}C_i}{T_i}$最大,设$\frac{F - \sum_{i}C_i}{T_i} \geq e$,移 ...

  8. hibernate mapping文件中 xmlns会导致linq to xml 查询不到对应的节点

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  9. jquery extend 多个扩展方法

    $.fn.extend({ SetDict: function (option) { var txtControl = $(this); if (!txtControl.hasClass(" ...

  10. CentOS7虚拟机安装Linux教程及安装后所遇到的问题

    1.VMware Workstation15下载. 官方链接:http://download3.vmware.com/software/wkst/file/VMware-workstation-ful ...