The All-purpose Zero

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

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.

 
0可以转化成任意整数,包括负数,显然求LIS时尽量把0都放进去必定是正确的。
为了保证严格递增,我们可以将每个权值S[i]减去i前面0的个数,再做LIS,就能保证结果是严格递增的。
/* ***********************************************
Author :guanjun
Created Time :2016/7/28 15:51:43
File Name :p410.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 100010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
int x,y;
};
struct cmp{
bool operator()(Node a,Node b){
if(a.x==b.x) return a.y> b.y;
return a.x>b.x;
}
}; bool cmp(int a,int b){
return a>b;
}
int d[maxn];
int a[maxn];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int T,n,cnt;
cin>>T;
for(int t=;t<=T;t++){
cin>>n;
for(int i=;i<=n;i++)scanf("%d",&a[i]);
int len=;
cnt=;
for(int i=;i<=n;i++){
if(a[i]==)cnt++;
else {
a[i]-=cnt;
int pos=lower_bound(d,d+len,a[i])-d;
if(pos==len){
d[len++]=a[i];
}
else d[pos]=a[i];
}
}
printf("Case #%d: %d\n",t,len+cnt);
}
return ;
}

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

  1. HDU 5813 Elegant Construction(优雅建造)

    HDU 5813 Elegant Construction(优雅建造) Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65 ...

  2. HDU 5813 Elegant Construction (贪心)

    Elegant Construction 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5813 Description Being an ACMer ...

  3. HDU 3072 Intelligence System (强连通分量)

    Intelligence System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  4. hdu 3038 How Many Answers Are Wrong

    http://acm.hdu.edu.cn/showproblem.php?pid=3038 How Many Answers Are Wrong Time Limit: 2000/1000 MS ( ...

  5. HDU 5813 Elegant Construction 构造

    Elegant Construction 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5813 Description Being an ACMer ...

  6. HDU 3038 - How Many Answers Are Wrong - [经典带权并查集]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3038 Time Limit: 2000/1000 MS (Java/Others) Memory Li ...

  7. HDU 3038 How Many Answers Are Wrong 【YY && 带权并查集】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=3038 How Many Answers Are Wrong Time Limit: 2000/1000 ...

  8. HDU 1937 J - Justice League

    J - Justice League Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  9. HDU 2435 There is a war

    There is a war Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ...

随机推荐

  1. cacheStorage缓存及离线开发

    案例地址:https://zhangxinxu.github.io/https-demo/cache/start.html 我们直接看一个例子吧,如下HTML和JS代码: <h3>一些提示 ...

  2. Java设计模式之策略模式(Strategy Pattern)

    简介 策略模式定义了算法族,分别封装起来,让它们之间可以互相替换,此模式让算法的变化独立于使用算法的客户. 组成 1.抽象策略角色(Strategy): 策略类,通常由一个接口或者抽象类实现. 2.具 ...

  3. docker安装配置lnmp

    一.安装配置docker 1.下载docker:yum install -y docker 2.设置docker远程镜像地址为国内路径:curl -sSL https://get.daocloud.i ...

  4. 洛谷 2187 小Z的笔记

    [题解] DP.  设f[i]表示前i个字母,保留第i个字母,最多可以保留多少个字母:设g[i]为当前字母为i的位置对应的f的最大值. 转移方程就是f[i]=max(f[i], g[j]+1) (j与 ...

  5. allegro中出光绘文件遇到问题的解决办法

    一:设置好光绘文件参数后,选择check dabase before artwork后,点击生成光绘时出现错误告警信息:    database has errors:artwork generati ...

  6. 【转】jquery 注册事件的方法

    原文链接:http://outofmemory.cn/code-snippet/2123/jquery-zhuce-event-method 1.使用事件名来绑定,可用的事件名有 change,cli ...

  7. Android RoundedBitmapDrawable:Android官方的圆角图形图象实现方案

     Android RoundedBitmapDrawable:Android官方的圆角图形图象实现方案 RoundedBitmapDrawable是Android在support v4的扩展包中新 ...

  8. poj 1733离散化(map)+并查集

    http://blog.sina.com.cn/s/blog_803d08c00100y2yy.html #include<stdio.h> #include<iostream> ...

  9. 天才的记忆(vijos 1514)

    描述 从前有个人名叫W and N and B,他有着天才般的记忆力,他珍藏了许多许多的宝藏.在他离世之后留给后人一个难题(专门考验记忆力的啊!),如果谁能轻松回答出这个问题,便可以继承他的宝藏.题目 ...

  10. Linux下C编程入门(7)

    Linux下项目同步工具介绍git和github 一.远程仓库工具github 1. 一.本地操作工具git 1.