C. Almost Arithmetical Progression (cf)
来源:互联网 发布:整形医院网络咨询工资 编辑:程序博客网 时间:2024/06/05 12:37
因为有重复的数,就让hi[]记录其值。go[]记录值对应的其中一个值的序列号。这样就把
具有相同值的数统一起来了。
昨天都是对的,今天发现自己提交的又被判成错误了,看来自己随便想的东东还是很容易有各种漏洞啊。
自己找了一下,也不知道有什么例子不对的。真不好意思
仅供小小的参考
#include<iostream>#include<cstdio>#include<string>#include<cstring>#include<algorithm>using namespace std;int go[1111111]={0};int b[5000];int main(){int i,j,k;int n;cin>>n;int hi[5000];for (i=0;i<n;i++){cin>>hi[i];go[hi[i]]=i;}memset(b,false,sizeof(b));int dp[5000];int ans=0;for (i=0;i<n;i++){int cur=i;for (j=0;j<n;j++)dp[j]=0,b[j]=-1;for (j=i+1;j<n;j++){//cout<<b[go[hi[j]]]<<' '<<cur<<endl;if (hi[i]==hi[j]){cur=j;}else if (b[go[hi[j]]]<cur){//cout<<i<<j<<"FUck";b[go[hi[j]]]=j;dp[go[hi[j]]]+=2;//cout<<hi[j]<<' '<<dp[go[hi[j]]]<<endl;}}for (j=0;j<n;j++){if (cur>b[go[hi[j]]] && !(dp[go[hi[j]]]&1))dp[go[hi[j]]]++;//cout<<j<<' '<<b[go[hi[j]]]<<endl;ans=max(ans,dp[go[hi[j]]]);//cout<<" "<<ans<<" ";}}cout<<ans<<endl;return 0;}
Gena loves sequences of numbers. Recently, he has discovered a new type of sequences which he called an almost arithmetical progression. A sequence is analmost arithmetical progression, if its elements can be represented as:
- a1 = p, wherep is some integer;
- ai = ai - 1 + ( - 1)i + 1·q(i > 1), whereq is some integer.
Right now Gena has a piece of paper with sequence b, consisting ofn integers. Help Gena, find there the longest subsequence of integers that is an almost arithmetical progression.
Sequence s1, s2, ..., sk is a subsequence of sequenceb1, b2, ..., bn, if there is such increasing sequence of indexesi1, i2, ..., ik(1 ≤ i1 < i2 < ... < ik ≤ n), thatbij = sj. In other words, sequences can be obtained fromb by crossing out some elements.
The first line contains integer n (1 ≤ n ≤ 4000). The next line contains n integersb1, b2, ..., bn(1 ≤ bi ≤ 106).
Print a single integer — the length of the required longest subsequence.
23 5
2
410 20 10 30
3
In the first test the sequence actually is the suitable subsequence.
In the second test the following subsequence fits: 10, 20, 10.
- C. Almost Arithmetical Progression (cf)
- cf 156.div2 C Almost Arithmetical Progression
- CF 156 C Almost Arithmetical Progression
- cf#156-C. Almost Arithmetical Progression-DP
- CF 255 C Almost Arithmetical Progression
- CF - 255C - Almost Arithmetical Progression(dp)
- CF#255 C. Almost Arithmetical Progression (DP)
- CodeForces 255C. Almost Arithmetical Progression (DP)
- Codeforces 255C Almost Arithmetical Progression DP
- Almost Arithmetical Progression
- Almost Arithmetical Progression
- codeforces 255C C. Almost Arithmetical Progression(dp)
- codeforces 255C C. Almost Arithmetical Progression(dp)
- codeforces 156C Almost Arithmetical Progression (离散化+dp)
- Codeforces Round #156 (Div. 2) C. Almost Arithmetical Progression
- Codeforces 256A Almost Arithmetical Progression【dp】
- CF-567C - Geometric Progression
- CF 567C. Geometric Progression
- MINA2.0用户手册中文版--第三章 第四节 客户端接口IoConnector
- hdu1072 BFS
- 关于oop定位错误的学习
- android 模拟器手机如何添加文件到sd卡
- oops信息的分析
- C. Almost Arithmetical Progression (cf)
- android中ExpandableListView点击哪一条那一条显示,而其他条隐藏的实现办法
- 搭建环境(1)
- 电子书下载:DELPHI 5 数据库开发技术
- < Unity 3D专栏 >游戏中 - 怪物AI基础篇
- 电子书下载:Delphi 7 从入门到精通
- 动态规划算法之矩阵连乘 及最长公共字符串多种解法源码
- 电子书下载:Delphi下深入Windows核心编程
- 电子书下载:Delphi Win32核心API参考(白金版)