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, ...
随机推荐
- express源码学习
终于腾出手来学习express.express在node.js中一株独秀.好像任何一种有主导的托管平台的语言,都出现这现象--马太效应.express是社区的共同孩子,里面聚集上社区最好的常用模块.从 ...
- Redhat 下添加用户到docker用户组
1. 检查系统中是否存在docker用户组,如果没有则手动添加 # sudo cat /etc/group |grep docker # sudo grouped -g 999 docker # -g ...
- PHP中file_exists()判断中文文件名无效的解决方法
php中判断文件是否存在我们会使用file_exists函数或is_file函数,但在使用file_exists时如果你文件名或路径是中文在uft8编码文档时是无效.本文就来解决此问题,下面我们一起来 ...
- iPython notebook 安装使用
pip install jupyter jupyter notebook --allow-root
- js格式化时间和时间操作
js格式化时间 function formatDateTime(inputTime) { var date = new Date(inputTime); var y = date.getFullYea ...
- Unity3D Asset 导入&导出
[Unity3D Asset 导入&导出] 通过Assets->Export Package..菜单可以导出当前选中Assets.若没有选中Assets,则会导出全部assets. 在弹 ...
- elasticsearch2.x插件之一:kopf
kopf kopf is a simple web administration tool for elasticsearch written in JavaScript + AngularJS + ...
- 卡尔曼滤波总结——KF、EFK、UKF
1.用途 现实是我们的处理和测量模型都是非线性的,结果就是一个不规则分布,KF能够使用的前提就是所处理的状态是满足高斯分布的,为了解决这个问题,EKF是寻找一个线性函数来近似这个非线性函数,而UKF就 ...
- 使用RVM更新Ruby 版本
http://rvm.io/rvm/install Install RVM (development version): \curl -sSL https://get.rvm.io | bash Wi ...
- Hadoop完全分布式环境搭建(二)——基于Ubuntu16.04设置免密登录
在Windows里,使用虚拟机软件Vmware WorkStation搭建三台机器,操作系统Ubuntu16.04,下面是IP和机器名称. [实验目标]:在这三台机器之间实现免密登录 1.从主节点可以 ...