您的位置:首页 > 其它

POJ 3298 Antimonotonicity (思维)

2016-08-30 13:15 489 查看
题目链接:http://poj.org/problem?id=3298

找一个最长不要求连续的子序列,如a1 > a3 < a6 > a7 ...

举个例子模拟一下差不多明白了,a[i - 1]与a[i]有依赖关系。

//#pragma comment(linker, "/STACK:102400000, 102400000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int N = 1e5 + 5;
int a
;

int main()
{
int t, n;
scanf("%d", &t);
while(t--) {
scanf("%d", &n);
for(int i = 1; i <= n; ++i) {
scanf("%d", a + i);
}
int Max = 1, num = a[1];
for(int i = 2; i <= n; ++i) {
if(Max % 2 && a[i] < num) {
Max++;
} else if(Max % 2 == 0 && a[i] > num) {
Max++;
}
num = a[i];
}
printf("%d\n", Max);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: