The All-purpose Zero

Problem Description
?? gets an sequence S with n intergers(0 < n <= 100000,0<= S[i] <= 1000000).?? has a magic so that he can change 0 to any interger(He does not need to change all 0 to the same interger).?? wants you to help him to find out the length of the longest increasing (strictly) subsequence he can get.

Input
The first line contains an interger T,denoting the number of the test cases.(T <= 10)
For each case,the first line contains an interger n,which is the length of the array s.
The next line contains n intergers separated by a single space, denote each number in S.

Output
For each test case, output one line containing “Case #x: y”(without quotes), where x is the test case number(starting from 1) and y is the length of the longest increasing subsequence he can get.

Sample Input
2
7
2 0 2 1 2 0 5
6
1 2 3 3 0 0

Sample Output
Case #1: 5
Case #2: 5

HintIn the first case,you can change the second 0 to 3.So the longest increasing subsequence is 0 1 2 3 5.

#include<cstdio>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
int pa[100011];
int st[100011];
int ma[100011];//建立一个全新的没有 0 的数组
int main()
{int i;int l;int T;int N;int num;int ans;int test=1;scanf("%d",&T);while(T--){scanf("%d",&N);for(i=1;i<=N;i++)scanf("%d",&pa[i]);fill(st+1,st+1+N,INF);num=0;l=1;for(i=1;i<=N;i++){if(pa[i]==0)//找出零的个数num++;else{pa[i]-=num;//减去当前 0 的个数ma[l++]=pa[i];}}ans=0;for(i=1;i<l;i++){int k=lower_bound(st+1,st+1+N,ma[i])-st;st[k]=min(st[k],ma[i]);//更新尾数ans=max(ans,k);//更新最优解}printf("Case #%d: %d\n",test++,ans+num);}return 0;
}

【HDU 杭电 5773 The All-purpose Zero】相关推荐

  1. 杭电1042c语言循环,HDU杭电1052 Tian Ji - The Horse Racing答题报告

    HDU杭电1052 Tian Ji -- The Horse Racing解题报告 本人第一次写博客,希望各位大神多多指导与包涵,不足的地方还请指出,新手在此谢过啦!!! 题目描述: Time Lim ...

  2. HDU杭电OJ经典100题2000-2099_Java版详细题解(持续更新)

    今年寒假打算用Java把杭电2000-2099全部AC(现在持续更新),如下是题目链接,之后是我的题解,全部做完后我会把所有AC的题解打包上传的 题号 题名 题号 题名 2000 ASCII码排序 2 ...

  3. HDU杭电ACMOJ训练指南

    以下题均为杭电acm网页的题号 首页http://acm.hdu.edu.cn/ 题库入口http://acm.hdu.edu.cn/listproblem.php?vol=1 帮助http://ac ...

  4. hdu 杭电题目分类

    View Code 1 1001 这个就不用说了吧 2 1002 简单的大数 3 1003 DP经典问题,最大连续子段和 4 1004 简单题 5 1005 找规律(循环点) 6 1006 感觉有点B ...

  5. hdu 杭电 1045 Fire Net

    题意:地图中最多能放多少炮台. 解法:深搜. ac代码: View Code #include<iostream> using namespace std;char map[8][8]; ...

  6. HDU杭电2066 - 一个人的旅行(Dijkstra算法)

    2018-5-1 今天抽时间看了最短路的几种算法: 这道题目用的是Dijkstra算法,算法的主要思想是按照路径长度递增的次序产生最短路径. 对于这个题目而言,需要注意的是: 1)赋值是双向的,比如说 ...

  7. hdu(杭电oj)第一页题目题解

    第一页有几题没写,有机会补上(嗯,忘了就是另一回事了). 这个是无聊的时候刷了第一页..存到博客上当做纪念吧.. hdu1000 简单题 难度1 计算a+b的值 hdu1001 简单题 难度1 计算1 ...

  8. hdu 杭电1429 胜利大逃亡(续)

    题目表述 Ignatius再次被魔王抓走了(搞不懂他咋这么讨魔王喜欢)-- 这次魔王汲取了上次的教训,把Ignatius关在一个n*m的地牢里,并在地牢的某些地方安装了带锁的门,钥匙藏在地牢另外的某些 ...

  9. 【HDU 杭电 5671 Matrix】

    Matrix Problem Description There is a matrix M that has n rows and m columns (1≤n≤1000,1≤m≤1000).The ...

  10. HDU杭电1052 Tian Ji -- The Horse Racing解题报告

    本人第一次写博客,希望各位大神多多指导与包涵,不足的地方还请指出,新手在此谢过啦!!! 题目描述: Time Limit: 2000/1000 MS (Java/Others)    Memory L ...

最新文章

  1. 世界创新竞争力发展报告:中美日创新产出竞争力居前三
  2. 为什么不应该使用(长期存在的)功能分支
  3. 计算机应用基础授课提纲,《计算机应用基础》讲授提纲(1).ppt
  4. 关于ArcGIS Rest API
  5. @程序员,欠下的技术债怎么还?
  6. java 导出excel 有图表的_java导出excel图表
  7. Web前端开发(一)--html基本结构,基本标签
  8. Pre-trained Adversarial Perturbations-对抗机器学习论文
  9. 苹果健康app+有android,苹果官方认证,这8款App最佳,你有几个?
  10. vue3 watch 异步方法
  11. 现代服务业行业税收筹划,信息技术公司节税方案
  12. Python代码实战(初级篇)————4、猜数字
  13. 蓝旭后端第六次培训课 MySQL(二)
  14. Java连接sqlserver数据库,并进行增删改查操作
  15. vue版本的仿京东放大镜代码还有原生js版本的。(组件封装)
  16. 富文本编辑器 图片base64 图片替换
  17. 基于uml的大学图书馆图书信息管理系统设计实验_气味图书馆 | 这些学校的#后悔没读#和#还想再读#系列...
  18. 读取SolidWorks文档中的属性,生成PDF(工具开发)
  19. 关于网络游戏防沉迷系统
  20. 数据结构第二章-线性表(详细知识点总结)

热门文章

  1. 月饼(python)
  2. 统计数组中英文大写字母,小写字母,数字,空格的个数。
  3. 百度地图全方位解析(一)
  4. redis集群和redis宕机处理方案
  5. [每日一氵] Harris代码
  6. 使用阿里云的ip地址查询服务-购买ip地址查询服务
  7. 详解String的intern方法
  8. 【参考文献】支气管上皮细胞培养方法
  9. Python爬取Google图片(2021.11.21编写)
  10. 英文缩写400个速查