题目描述
Recently,Nero is researching a kind of sequence problem related to the sphere.This kind of problem ressembles the Longest Ascending Subsequence.
For instance,Given a sequence,can you find the longest subsequence in it?
Following constraints should be meeted:
1:the elements in the subsequence should be totally equal.
2:the interval between the adjacent elements in the subsequence shouldn't be greater than one(in the hint,we'll show clearly what the interval is)
输入格式
T indicating the number of test cases
Each case begins with a interger
n(0<=n<=1000)
,representing the length of sequence
Following are n integers,Pi stands for the value of each element.
输出格式
One line,contains a integer indicating the length of the longest subsequence.
输入样例
2
6
1 2 2 1 1 1
8
1 2 2 2 1 1 1 1
输出样例
3
4
题干提到的LAS真够坑的... 明明没有关系的, sample给的偏偏就是模糊不清, 理解为LAS也可以得出相同结果
其实简单的很, 没理解题目意思, 结果自然是WA了以后立刻就发现了, 理解了就好简单...
事实上题目意思是要找一个最长的相同元素构成的序列, 使得相邻两项的位置差不超过1...也就是最多可以跳一位取下一项
思路是简单的dp, 毫无技术含量......能不跳就不跳, 其实说是贪心也对? 撒~~
/*
USER_ID: test#birdstorm
PROBLEM: 183
SUBMISSION_TIME: 2014-03-08 01:07:10
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define MAX(x,y) (x)>(y)?(x):(y)
#define For(i,m,n) for(i=m;i<n;i++)
#define MAXN 1005
int a[MAXN], dp[MAXN];
main()
{
int i, j, n, t, len, max;
scanf("%d",&t);
while(t--){
len=1; max=0;
dp[0]=1;
scanf("%d%d",&n,&a[0]);
For(i,1,n){
scanf("%d",&a[i]);
if(a[i]==a[i-1]) dp[i]=dp[i-1]+1;
else if(a[i]==a[i-2]) dp[i]=dp[i-2]+1;
else dp[i]=1;
}
For(i,0,n) max=MAX(max,dp[i]);
printf("%d\n",max);
}
return 0;
}