The All-purpose Zero

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 584    Accepted Submission(s): 278

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

Hint

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

 
Author
FZU
思路:0可以变为任何的数,考虑到底以一个数的结尾的最长上升序列,加入前面有0的个数多少来变化能使这个长度变为最长,因为要加入0来变化,所以一定可以改变0的大小来使这个序列递增,但是插入0是有花费的,比如4 0 5;那么这个时候只能让当前的数减去前面0的个数,来抵消这个花费,因为每个0只消耗一点花费,所以将前面所有0加入,可保证到这个
数的序列最长。然后先将非0的求LIS,末尾加个最大值,然后加上前面的0,求最大;
 1 #include <cstdio>
2 #include <cstdlib>
3 #include <cstring>
4 #include <cmath>
5 #include <iostream>
6 #include <algorithm>
7 #include <map>
8 #include <queue>
9 #include <vector>
10 using namespace std;
11 typedef long long LL;
12 int arr[100005];
13 int id[100005];
14 int a[100005];
15 int add[100005];
16 int c[100005];
17 int main(void)
18 {
19 int i,j,k;
20 scanf("%d",&k);
21 int __ca=0;
22 while(k--)
23 {
24 __ca++;
25 int cnt;
26 memset(c,0,sizeof(c));
27 scanf("%d",&cnt);
28 for(i=1; i<=cnt; i++)
29 {
30 scanf("%d",&a[i]);
31 }
32 a[cnt+1]=1e9;
33 cnt++;
34 for(i=1; i<=cnt; i++)
35 {
36 if(a[i]==0)
37 {
38 c[i]=c[i-1]+1;
39 }
40 else
41 {
42 c[i]=c[i-1];
43 }
44 }
45 int ans=1;
46 for(i=1; i<=cnt; i++)
47 {
48 if(a[i]!=0)
49 {
50 arr[ans]=a[i]-c[i];
51 add[ans]=c[i];
52 ans++;
53 }
54 }
55 id[1]=arr[1];
56 int maxx=1;
57 int ac=0; ac=max(ac,add[1]+maxx);
58 for(i=2; i<ans; i++)
59 {
60 if(arr[i]>id[maxx])
61 {
62 maxx++;
63 id[maxx]=arr[i];
64 ac=max(ac,add[i]+maxx);
65 }
66 else
67 {
68 if(arr[i]==id[maxx])
69 continue;
70 else
71 {
72 int ask=0;
73 int l=1;
74 int r=maxx;
75 while(l<=r)
76 {
77 int mid=(l+r)/2;
78 if(id[mid]<=arr[i])
79 {
80 ask=mid;
81 l=mid+1;
82 }
83 else r=mid-1;
84 }
85 ac=max(ac,add[i]+ask+1);
86 maxx=max(maxx,ask+1);
87 id[ask+1]=min(id[ask+1],arr[i]);
88 }
89 }
90 }
91 printf("Case #%d: %d\n",__ca,ac-1);
92 }
93 return 0;
94 }

The All-purpose Zero(hdu5773)的更多相关文章

  1. 《理解 ES6》阅读整理:函数(Functions)(六)Purpose of Functions

    明确函数的双重作用(Clarifying the Dual Purpose of Functions) 在ES5及更早的ES版本中,函数调用时是否使用new会有不同的作用.当使用new时,函数内的th ...

  2. Reading With Purpose: A grand experiment

    Reading With Purpose: A grand experiment This is the preface to a set of notes I'm writing for a sem ...

  3. General Purpose Hash Function Algorithms

    General Purpose Hash Function Algorithms post@: http://www.partow.net/programming/hashfunctions/inde ...

  4. libeXosip2(2) -- General purpose API.

    General purpose API. general purpose API in libeXosip2-4.0.0. More... Modules eXosip2 configuration ...

  5. However, a general purpose protocol or its implementation sometimes does not scale very well.

    https://netty.io/wiki/user-guide-for-4.x.html The Problem Nowadays we use general purpose applicatio ...

  6. Purpose of ContextLoaderListener in Spring

    The ApplicationContext is where your Spring beans live. The purpose of the ContextLoaderListener is ...

  7. iOS 后台定位审核被拒How to clarify the purpose of its use in the locatio

    4.5 - Apps using background location services must provide a reason that clarifies the purpose of th ...

  8. Purpose of XMLString::transcode

    原文地址http://stackoverflow.com/questions/9826518/purpose-of-xmlstringtranscode I don't seem to underst ...

  9. Oracle Multitenant Environment (二) Purpose

    Purpose of a Multitenant Environment A multitenant environment enables the central management of mul ...

  10. PatentTips - Safe general purpose virtual machine computing system

    BACKGROUND OF THE INVENTION The present invention relates to virtual machine implementations, and in ...

随机推荐

  1. C++ 中的多重继承的问题

    如何正确使用C++多重继承 BY R12F · PUBLISHED 2011年06月17日 · UPDATED 2012年03月11日   原创文章,转载请注明:转载自Soul Apogee本文链接地 ...

  2. 日常Java 2021/10/18

    Vecter类实现了一个动态数组,不同于ArrayList的是,Vecter是同步访问的, Vecter主要用在事先不知道数组的大小或可以改变大小的数组 Vecter类支持多种构造方法:Vecter( ...

  3. Angular Service设计理念及使用

    官方认为组件不应该直接获取或保存数据, 它们应该聚焦于展示数据,而把数据访问的职责委托给某个服务. 而服务就充当着数据访问,逻辑处理的功能.把组件和服务区分开,以提高模块性和复用性. 1.依赖注入 注 ...

  4. SSH服务及通过SSH方式登录linux

    SSH服务及通过SSH方式登录linux 1.检查SSH服务转自:[1]Linux之sshd服务https://www.cnblogs.com/uthnb/p/9367875.html[2]Linux ...

  5. Linux:变量$#,$@,$0,$1,$2,$*,$$,$?

    写一个简单的脚本 vim var 脚本内容如下: #!/bin/sh echo "the number of parameters passed to the script: $#" ...

  6. Spring中Bean的装配方式

    一.基于xml的装配 Student.java package com.yh; public class Student implements People { public void breath( ...

  7. Taro 3.5 canary 发布:支持适配 鸿蒙

    一.背景 鸿蒙作为华为自研开发的一款可以实现万物互联的操作系统,一经推出就受到了很大的关注,被国人寄予了厚望.而鸿蒙也没让人失望,今年 Harmony2.0 正式推出供用户进行升级之后,在短短的三个月 ...

  8. 【C/C++】n皇后问题/全排列/递归/回溯/算法笔记4.3

    按常规,先说一下我自己的理解. 递归中的return常用来作为递归终止的条件,但是对于返回数值的情况,要搞明白它是怎么返回的.递归的方式就是自己调用自己,而在有返回值的函数中,上一层的函数还没执行完就 ...

  9. 【C#】【MySQL】C#连接MySQL数据库(一)代码

    C#连接MySQL数据库 准备工作 1.环境安装 安装MySQL For Visual Studio<<点击进入官网下载 第一个要下载安装,第二个下载后将MySQL.data添加到Visu ...

  10. 2、Redis的安装

    一.Windows下Redis安装 下载地址 Redis中文网站 Github地址 1.将下载下来的文件解压到目录 2.双击redis-server.exe运行   出现如下界面证明运行成功 3.双击 ...