Antimonotonicity
来源:互联网 发布:sql基础教程 第二版 编辑:程序博客网 时间:2024/04/30 22:51
Description
给你1-N的一个排列,数列中的数字互不相等,要求找出最长的子序列a,满足a1 > a2,a2 < a3,a3 > a4,a4 < a5……
The solution
乍一眼看过去,有点亲切,最长不下降子序列?差不多。。。dp?有搞头。。。
于是乎边埋头开打。。。结果被题解逗了。。(*  ̄︿ ̄)
题解很简单,设一个last,记录之前取得数,因为题目要求的是像山峰似得数列,大概像
这样吧:“W”,汗。。,于是可以把下降的标记为true,把上升的标记为false,之后再yy
具体如下:
如果现在取了奇数个(即为要下降的),即要取的小于之前最后取的,若目前的数a[i]>last,则将last用a[i]替换,否则取a[i];
如果现在取了偶数个(即为要上升的),即要取的大于之前最后取的,若目前的数a[i]
code
#include <cstdio>#include <iostream>#include <cmath>#include <cstring>#include <algorithm>#define fo(i,a,b) for (int i=a;i<=b;i++)#define fd(i,a,b) for (int i=a;i>=b;i--)#define N 30005using namespace std;int main(){ int T,n,x; scanf("%d",&T); while (T--) { scanf("%d",&n); scanf("%d",&x); int last=x,ans=1; bool mark=false; fo(i,2,n) { scanf("%d",&x); if ((!mark && x<=last) || (mark && x>=last)) ans++,mark=!mark; last=x; } printf("%d\n",ans); }}
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(贪心)
- 求一组数的所有组合。
- 洛谷 P1969 积木大赛
- 开发者提交产品前需要注意的几个点
- 在Java的Hibernate框架中对数据库数据进行查询操作
- 后序中序——>前序
- Antimonotonicity
- J2EE开发---验证码(二)----kaptcha框架
- RabbitMq、ActiveMq、ZeroMq、kafka之间的比较,资料汇总
- 【BZOJ1834】[ZJOI2010]network 网络扩容【最大流】【最小费用最大流】【残量网络】
- apache,php常用配置
- java.util.concurrent源码学习四
- {小结}2016.07.14【初中部 NOIP提高组 】模拟赛B
- poj1410 intersection
- 死锁