题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5773

0可以改变成任何数,问你严格递增的子序列最长是多少。

猜测0一定在最长上升子序列中用到,比如2 0 0 3 5 6,可以变为2 3 4 3 5 6。

那我们先算出0的个数,然后每次遇到0就把后面一开始不是0的-1,算出剩下数的最长上升子序列(nlogn),然后加上0的个数。

 //#pragma comment(linker, "/STACK:102400000, 102400000")
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
typedef pair <int, int> P;
const int N = 1e5 + ;
int inf = 0x3f3f3f3f;
int a[N], dp[N], b[N]; // dp[i]:长度为i的上升子序列中最后元素的最小值 int main()
{
int t, n;
scanf("%d", &t);
for(int ca = ; ca <= t; ++ca) {
scanf("%d", &n);
int dec = , index = ;
for(int i = ; i <= n; ++i) {
scanf("%d", a + i);
if(a[i] == ) {
++dec;
} else {
a[i] -= dec;
b[++index] = a[i];
}
dp[i] = inf;
}
for(int i = ; i <= index; ++i) {
*lower_bound(dp + , dp + index + , b[i]) = b[i];
}
printf("Case #%d: %d\n", ca, lower_bound(dp + , dp + n + , inf) - dp - + dec);
}
return ;
}

HDU 5773 The All-purpose Zero (变形LIS)的更多相关文章

  1. hdu 5773 The All-purpose Zero 最长上升子序列+树状数组

    题目链接:hdu 5773 The All-purpose Zero 官方题解:0可以转化成任意整数,包括负数,显然求LIS时尽量把0都放进去必定是正确的. 因此我们可以把0拿出来,对剩下的做O(nl ...

  2. HDU 3094 树上删边 NIM变形

    基本的树上删边游戏 写过很多遍了 /** @Date : 2017-10-13 18:19:37 * @FileName: HDU 3094 树上删边 NIM变形.cpp * @Platform: W ...

  3. HDU 5773 The All-purpose Zero(O(nlgn)求LIS)

    http://acm.hdu.edu.cn/showproblem.php?pid=5773 题意: 求LIS,其中的0可以看做任何数. 思路: 因为0可以看做任何数,所以我们可以先不管0,先求一遍L ...

  4. HDU 5773:The All-purpose Zero(贪心+LIS)

    http://acm.hdu.edu.cn/showproblem.php?pid=5773 The All-purpose Zero Problem Description   ?? gets an ...

  5. HDU 5773 The All-purpose Zero 求LIS

    求最长上升子序列长度: 单纯的dp时间复杂度是O(n*n)的 dp[i] = max(dp[j]+1); (0=<j<=i-1 && a[i]>a[j]) 用二分可以 ...

  6. HDU 5773 The All-purpose Zero 脑洞LIS

    给定一个序列,里面的0是可以任变的.问变化后最长的LIS的长度 首先,0全部选上是不亏的.这个不知道怎么说,YY一下吧. 最关键的就是解决2 0 0 3 这种问题了. 注意到这个序列的LIS应该是3 ...

  7. HDU 1087 Super Jumping! Jumping! Jumping! ——(LIS变形)

    和之前那个长方体最大高度是换汤不换药的题目.每次找之前最大的一个能接的接上即可.代码如下: #include <stdio.h> #include <algorithm> #i ...

  8. hdu 5773 The All-purpose Zero 线段树 dp

    The All-purpose Zero 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5773 Description ?? gets an seq ...

  9. 【动态规划】【二分】【最长上升子序列】HDU 5773 The All-purpose Zero

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5773 题目大意: T组数据,n个数(n<=100000),求最长上升子序列长度(0可以替代任何 ...

随机推荐

  1. git for windows+TortoiseGit客户端的使用

        一.安装Git客户端 全部安装均采用默认! 1. 安装支撑软件 : https://code.google.com/p/msysgit/downloads/list?q=full+instal ...

  2. Android消息推送完美解决方案全析

    推送功能在手机应用开发中越来越重要,已经成为手机开发的必须.在Android应用开发中,由于众所周知的原因,Android消息推送我们不得不大费周折.本文就是用来和大家共同探讨一种Android消息推 ...

  3. sql server删除数据后空间无变化处理方法

    删除数据库表 第一步: 执行 delete from doc.115sou.com        #删除数据,执行效率低 drop table doc.115sou.com          #删除表 ...

  4. Spring下载

    Spring官网改版后找了好久都没有找到直接下载Jar包的链接,下面汇总些网上提供的方法,亲测可用. 1.直接输入地址,改相应版本即可:http://repo.springsource.org/lib ...

  5. Web Api 接口文档制作

    参考地址: http://blogs.msdn.com/b/yaohuang1/archive/2012/05/21/asp-net-web-api-generating-a-web-api-help ...

  6. hdu 4609 3-idiots(快速傅里叶FFT)

    比较裸的FFT(快速傅里叶变换),也是为了这道题而去学的,厚的白书上有简单提到,不过还是推荐看算法导论,讲的很详细. 代码的话是照着别人敲的,推荐:http://www.cnblogs.com/kua ...

  7. 脚本AI与脚本引擎

    Scripted AI and Scripting Engines 脚本AI与脚本引擎 This chapter discusses some of the techniques you can us ...

  8. 入门视频采集与处理(学会分析YUV数据)

    做视频采集与处理,自然少不了要学会分析YUV数据.因为从采集的角度来说,一般的视频采集芯片输出的码流一般都是YUV数据流的形式,而从视频处理(例如H.264.MPEG视频编解码)的角度来说,也是在原始 ...

  9. linux下网络排错与查看

    基本的故障排除错误 故障的排除一定是先简单后复杂的,有的人把上述的文件反复配置,就是上不了网,一直都认为是系统出了故障,想重装机子.结果发现原来是网线压根就没插上. 排错要慢慢的按部就班的来: (1) ...

  10. C# new用法总结

    有一道这样的题:写出c#中new关键字的三种用法,思前想后挖空心思也只想出了两种用法,回来查了下msdn,还真是有第三种用法: 用于在泛型声明中约束可能用作类型参数的参数的类型,这是在Framewor ...