ZCMU-1231-Antimonotonicity
来源:互联网 发布:windows驱动开发培训 编辑:程序博客网 时间:2024/04/18 02:40
1231: Antimonotonicity
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 33 Solved: 10
[Submit][Status][Web Board]
Description
I have a sequence Fred of length n comprised of integers between 1 and n inclusive. The elements of Fred are pairwise distinct. I want to find a subsequence Mary of Fred that is as long as possible and has the property that:
Mary[0] > Mary[1] < Mary[2] > Mary[3] < ...
Input
The first line of input will contain a single integer T expressed in decimal with no leading zeroes. T will be at most 50. T test cases will follow.
Each test case is contained on a single line. A line describing a test case is formatted as follows:
n Fred[0] Fred[1] Fred[2] ... Fred[n-1].
where n and each element of Fred is an integer expressed in decimal with no leading zeroes. No line will have leading or trailing whitespace, and two adjacent integers on the same line will be separated by a single space. n will be at most 30000.
Output
For each test case, output a single integer followed by a newline --- the length of the longest subsequence Mary of Fred with the desired properties.
Sample Input
Sample Output
#include<iostream>#include<cstring>#include<cstdio>#include<cstdlib>#include<algorithm>using namespace std;int main(){ int t,n,i,p,q,flag,count1; scanf("%d",&t); while(t--) { scanf("%d",&n); scanf("%d",&p); flag=1; count1=1; for(i=1;i<n;i++) { scanf("%d",&q); if(flag==1) { if(q<p) { count1++; flag=0; } p=q; } else { if(q>p) { count1++; flag=1; } p=q; } } printf("%d\n",count1); } return 0;}
- ZCMU-1231-Antimonotonicity
- 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)
- TOJ 2896.Antimonotonicity(贪心)
- zcmu-1657
- zcmu-1685
- ZCMU----1776
- ZCMU----1777
- ZCMU----1778
- MySQL Binary Log
- 弹出PopupWindow使屏幕变暗的效果
- 用@ExceptionHandler 来进行异常处理
- NATLAB中矩阵乘法与矩阵点乘(对应位相乘)
- Hadoop-2.7.3集群(HDFS)搭建
- ZCMU-1231-Antimonotonicity
- 清新脱俗的网页设计,给你不一样的视觉感受
- Linux下安装和配置Git
- hadoop自带示例wordcount
- leetcode 325 Maximum Size Subarray Sum Equals k
- cronolog分割Tomcat7的catalina.out
- 【背包专题——完全背包】
- android-studio下载安装
- boost.asio系列——Timer