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

Hint

 

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

 
英文题目难读,但是题意简单,就是给出一序列整数,0可以变成任意数,求出他的最长上升子序列的长度,必须例一,将2 0 5中的0变成3,最长子序列就是0 1 2 3 5。
 
对于这题不能直接求出最长上升子序列的长度,可以先让每个数减去它前面0的个数,再求出非0的数序列的最长上升子序列的长度,最后求出的长度加上零的数量。
 
假设让所有的零都进去最长连续子序列,例如a 0 0 0 b,可以先不看b,将a 0 0 0看成连续的上升序列,用b减去0的数量b-3,如果b-3>a说明a可以大于最后一个零的值,a b-3为非0数最长子序列,长度为2,加上0的个数,最后结果为5,如果b-3<a的值,说明最长子序列只能到最后一个零,a或b为非零数中最长子序列,长度为1,加上0的数量,最后结果为4,最后求的序列就是a 0 0 0(0为任意数)
 
 #include<cstdio>
#include<algorithm>
#define INF 0x3f3f3f3f
using namespace std;
int b[],g[];
int main()
{
int t,s=;
scanf("%d",&t);
while(t--)
{
int n,sum0=;
int i,a,j;
scanf("%d",&n);
int num=;
for(i = ; i <= n ; i++)
{
scanf("%d",&a);
g[i]=INF;
if(a == )
{
sum0++;
continue;
}
b[++num]=a-sum0; //记录每个数都减去前面的0的数量
}
int max0=;
for(i = ; i <= num ; i++)
{
int k=lower_bound(g+,g+num+,b[i])-g; //类似二分法,把b[i]的数存到g[i]中
max0=max0>k?max0:k; //直接记录最长子序列长度(相当于d[i]记录以第i个数结尾的子序列的最大长度,再比较d[i]的最大值)
g[k]=b[i];
}
printf("Case #%d: %d\n",++s,max0+sum0);
}
}

杭电 5773 The All-purpose Zero的更多相关文章

  1. acm入门 杭电1001题 有关溢出的考虑

    最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM( ...

  2. 杭电acm 1002 大数模板(一)

    从杭电第一题开始A,发现做到1002就不会了,经过几天时间终于A出来了,顺便整理了一下关于大数的东西 其实这是刘汝佳老师在<算法竞赛 经典入门 第二版> 中所讲的模板,代码原封不动写上的, ...

  3. 杭电OJ——1198 Farm Irrigation (并查集)

    畅通工程 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可 ...

  4. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  5. 高手看了,感觉惨不忍睹——关于“【ACM】杭电ACM题一直WA求高手看看代码”

    按 被中科大软件学院二年级研究生 HCOONa 骂为“误人子弟”之后(见:<中科大的那位,敢更不要脸点么?> ),继续“误人子弟”. 问题: 题目:(感谢 王爱学志 网友对题目给出的翻译) ...

  6. C#利用POST实现杭电oj的AC自动机器人,AC率高达50%~~

    暑假集训虽然很快乐,偶尔也会比较枯燥,,这个时候就需要自娱自乐... 然后看hdu的排行榜发现,除了一些是虚拟测评机的账号以外,有几个都是AC自动机器人 然后发现有一位作者是用网页填表然后按钮模拟,, ...

  7. 杭电ACM2076--夹角有多大(题目已修改,注意读题)

    杭电ACM2076--夹角有多大(题目已修改,注意读题) http://acm.hdu.edu.cn/showproblem.php?pid=2076 思路很简单.直接贴代码.过程分析有点耗时间. / ...

  8. 杭电ACM2092--整数解

    杭电ACM2092--整数解    分析 http://acm.hdu.edu.cn/showproblem.php?pid=2092 一个YES,一个Yes.试了10几次..我也是无语了..哪里都不 ...

  9. 杭电2034——人见人爱A-B

    #include <stdio.h> #include <algorithm> using namespace std; int main () { int a[110],b[ ...

随机推荐

  1. 响应式Spring Cloud初探

    响应式Spring Cloud初探 分类:工程原文链接:The Road to Reactive Spring Cloud作者:  JOSH LONG译者: helloworldtang日期:JUNE ...

  2. [问题解决]Deepin环境变量设置无效解决

    将环境变量的设置放在这里:  gedit ~/.bashrc 详见参考: linux下如何设置环境变量PATH : http://blog.csdn.net/witsmakemen/article/d ...

  3. block 应用说明

    一.Block定义 Block可以理解为一个函数指针(即它是一个指针,指向某个函数) returnType (^blockName) (parameter list) = ^ (parameter l ...

  4. NF!=1

    NF表示列数,不等于1表示列数不为1列

  5. Java文件操作系列[1]——PDFBox实现分页提取PDF文本

    需求:用java分页提取PDF文本. PDFBox是一个很好的可以满足上述需求的开源工具. 1.PDF文档结构 要解析PDF文本,我们首先要了解PDF文件的结构. 关于PDF文档,最重要的几点: 一, ...

  6. 你知道现在的.net是什么样的吗,一张图告诉你

    Here are these concepts used in an example sentence, for context: Application Framework - “Are you u ...

  7. Bootstrap 入门到精通

    介绍 Bootstrap,来自 Twitter,是目前最受欢迎的前端框架.Bootstrap 是基于 HTML.CSS.JAVASCRIPT 的,它简洁灵活,使得 Web 开发更加快捷.Bootstr ...

  8. 补题—Codeforces Round #346 (Div. 2) _智商欠费系列

    这次的题目相对容易 但是智商依旧不够用 原因有三点 1.英文水平堪忧 2 逻辑不严密 3 细节掌握不够好 传送门 http://codeforces.com/contest/659 A 题目大意 圆环 ...

  9. poj1142Smith Numbers质因子分解

    题意:一个数不是质数,其质因子的每位加起来等于该数的每位加起来. /* 题意:一个数的所有质因子的每位相加起来等于该数的每位相加起来且该数不能是质数,那么就是史密斯数 tip:对于分解质因子,只需要判 ...

  10. SayLove微信小程序

    目录 SayLove 表白墙微信小程序 程序结构 说明 程序效果图 配置过程 结语 云开发 quickstart 参考文档 SayLove 表白墙微信小程序 项目地址:https://github.c ...