Antimonotonicity
来源:互联网 发布:心动网络 有员工宿舍么 编辑:程序博客网 时间:2024/05/01 03:18
Antimonotonicity
Time Limits: 1000 ms Memory Limits: 128000 KB
Description
给你1-N的一个排列,数列中的数字互不相等,要求找出最长的子序列a,满足a1 > a2,a2 < a3,a3 > a4,a4 < a5……
Input
T 代表T组数据 T<=50
每组数据一行: n 代表给你n个数,然后就是n个数 N<=30000
Output
T行 每行一个数:
对于每组数据输出最长子序列的长度
Sample Input
45 1 2 3 4 55 5 4 3 2 15 5 1 4 2 35 2 4 1 3 5
Sample Output
1253
解题思路
题目就是让我们求最长的锯齿状序列的长度。
O(n)扫一遍,发现有“峰”就答案增加一。
证明易证。
#include<cstdio>#include<cstring>#define fo(i,x,y) for(int i=x;i<=y;i++)using namespace std;int t,n,a[30001];int Max(int,int,int);void pushMax(int num);int main(){ scanf("%d",&t); fo(i,1,t) { int ans=0; bool p=1; scanf("%d",&n); fo(i,1,n)scanf("%d",&a[i]); fo(i,1,n-1)if((p && a[i]>a[i+1])||((!p) && a[i]<a[i+1])){p=!p;ans++;} printf("%d\n",ans+1); }}
0 0
- Antimonotonicity
- Antimonotonicity
- Antimonotonicity
- TJU Antimonotonicity
- JZOJ1728. Antimonotonicity
- poj 3298 Antimonotonicity DP
- Sicily 1448. Antimonotonicity
- poj 3298 Antimonotonicity 贪心
- Sicily 1448. Antimonotonicity
- JZOJ.1728. Antimonotonicity
- Antimonotonicity (Standard IO)
- ZCMU-1231-Antimonotonicity
- TOJ 2896.Antimonotonicity(贪心)
- java之集合框架
- 数据挖掘概念与技术-学习笔记
- xilinx下载器驱动提示“系统找不到指定的路径”的解决过程
- fedora 软件安装
- 第一次使用CEF做个Demo
- Antimonotonicity
- java中新增的逻辑操作符"^"
- java之正则表达式
- Java数据类型
- Leetcode 92. Reverse Linked List II 翻转链表2 解题报告
- 单链表相关作用
- 圆形图片-----attrs.xml
- 安卓service
- 结构之法and算法之道(合集)