hdu-6570

Wave

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 237    Accepted Submission(s): 110


 

Problem Description

Avin is studying series. A series is called "wave" if the following conditions are satisfied:
1) It contains at least two elements;
2) All elements at odd positions are the same;
3) All elements at even positions are the same;
4) Elements at odd positions are NOT the same as the elements at even positions.
You are given a series with length n. Avin asks you to find the longest "wave" subseries. A subseries is a subsequence of a series.

 

 

Input

The first line contains two numbers n, c (1 ≤ n ≤ 100, 000, 1 ≤ c ≤ 100). The second line contains n integers whose range is [1, c], which represents the series. It is guaranteed that there is always a "wave" subseries.

 

 

Output

Print the length of the longest "wave" subseries.

 

 

Sample Input

 

5 3 1 2 1 3 2

 

 

Sample Output

 

4

 

 

Source

题意:给你n个数字,让你求“”wave“”序列的最值,什么是“”wave“”序列呢、

1: 此序列为给你序列的子序列:

2:wave序列上的奇数位置的所有的数字都相等,偶数位置的所有的序列也都相等,而且奇数位置上的数和偶数位置上的数不相等。

心得:这个题当时做的时候并没有什么思路,因为并不知道该从何处下手,后来开始看题解,看完后还是懂,然后又百度了别人的代码,才知道了怎么写,写好后提交直接TLE了,我感觉和别人写的一样,可是不知道为什么别人的就过了,我的就凉了,后来就开始优化,经过无数次的挫折才把这个题给过了,这个题真的是难为死我了。

题解:因为所给的数字不是太大,就是每个数字的大小都小于100,我们每次枚举两个数字就行了,记住用vector存,因为直接存的话是存不下的。当你枚举两个数字后,你会得到两个序列,这两个序列就是你枚举的那两个数字的在数组总所占有的位置,

然后想办法把这两个序列合到一起,假如两个数字相同,而且相邻,那么就把这两个数字当成同一个数字,最后求得序列的长度就是这个题的答案,

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值