poj 3298 Antimonotonicity 贪心
来源:互联网 发布:nginx负载均衡原理 编辑:程序博客网 时间:2024/04/30 17:19
题意:
求一个序列的最大子序列,该子序列满足:a1>a2<a3>a4.....。
分析:
贪心,从极大值起交替取这个序列中极小值、极大值。
代码:
//poj 3298//sep9#include <iostream>using namespace std;const int maxN=30024;int a[maxN];int main(){int cases;scanf("%d",&cases);while(cases--){int i,j,n,s=0;scanf("%d",&n);for(i=1;i<=n;++i)scanf("%d",&a[i]);int ans=1;for(i=1;i+1<=n;++i){if(a[i]>a[i+1]){s=0;++ans;for(j=i+1;j+1<=n;++j){if((s==0&&a[j]<a[j+1])||(s==1&&a[j]>a[j+1])){++ans;s=s^1;}}break;}}printf("%d\n",ans);}return 0;}
0 0
- poj 3298 Antimonotonicity 贪心
- poj 3298 Antimonotonicity DP
- TOJ 2896.Antimonotonicity(贪心)
- Antimonotonicity
- Antimonotonicity
- Antimonotonicity
- TJU Antimonotonicity
- JZOJ1728. Antimonotonicity
- Sicily 1448. Antimonotonicity
- Sicily 1448. Antimonotonicity
- JZOJ.1728. Antimonotonicity
- Antimonotonicity (Standard IO)
- ZCMU-1231-Antimonotonicity
- poj 1017 Packets【贪心】
- POJ 1017 Packets(贪心)
- POJ 1323 简单贪心
- POJ 1065 (贪心)
- POJ 1328 贪心
- 利用java反射处理excel数据导入示例
- SDUT14级队员训练1 A - Score
- OJ搭建详细
- 获取IPhone相册中图片的方法(包括获取所有图片)
- Android 四种布局
- poj 3298 Antimonotonicity 贪心
- 简单计算器
- RM指令长度及数据类型
- DedeCMS调用指定栏目不包含下级栏目的问题
- ParameterizedType的作用
- Cocos2d-x 3.x基础总结 -- 定时器更新schedule/update
- linux安装eclipse
- 用java存oracle数据库的date类型精确到秒【java.sql.Date 和java.util.Date的区别】
- Linux Shell下的后台运行及其前台的转换