C. Almost Arithmetical Progression (cf)

因为有重复的数,就让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;
}

C. Almost Arithmetical Progression
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

The first line contains integer n (1 ≤ n ≤ 4000). The next line contains n integersb1, b2, ..., bn(1 ≤ bi ≤ 106).

Output

Print a single integer — the length of the required longest subsequence.

Sample test(s)
Input
2
3 5
Output
2
Input
4
10 20 10 30
Output
3
Note

In the first test the sequence actually is the suitable subsequence.

In the second test the following subsequence fits: 10, 20, 10.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值