依据问题转换成最长不降子序列问题。

10^9的输入数据计算起来还是挺花时间的。由于这里仅仅能使用O(nlgn)时间复杂度了。

只是证明是能够算出10^9个数据的。

由于时间限制是5s.

#include <stdio.h>
#include <vector>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <limits.h>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std; const int MAX_N = 20;
vector<int> arr, a2;
int N; inline int lSon(int rt) { return rt<<1|1; }
inline int rSon(int rt) { return (rt<<1)+2; } void postOrder(int rt, int &v)
{
int l = lSon(rt), r = rSon(rt);
if (l < N) postOrder(l, v);
if (r < N) postOrder(r, ++v);
a2.push_back(arr[rt]-v);
} int biGetIndex(int low, int up, int v)
{
while (low <= up)
{
int mid = low + ((up-low)>>1);
if (v < a2[mid]) up = mid-1;
else low = mid+1;
}
return low;
} int LIS()
{
int j = 0;
for (int i = 1; i < N; i++)
{
if (a2[i] >= a2[j]) a2[++j] = a2[i];
else
{
int id = biGetIndex(0, j, a2[i]);
a2[id] = a2[i];
}
}
return j+1;
} int main()
{
int a;
scanf("%d", &N);
arr.clear(), a2.clear();
while (scanf("%d", &a) != EOF)
{
arr.push_back(a);
} N = (int) arr.size();
int v = 0;
postOrder(0, v);
int len = LIS();
printf("%d\n", N-len);
return 0;
}

Heap 3214 LIS题解的更多相关文章

  1. HDU4352 XHXJ's LIS 题解 数位DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4352 题目大意: 求区间 \([L,R]\) 范围内最长上升子序列(Longest increasin ...

  2. BZOJ3173:[TJOI2013]最长上升子序列 & HDU3564:Another LIS——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=3173 http://acm.hdu.edu.cn/showproblem.php?pid=3564 ...

  3. python数据结构之堆(heap)

    本篇学习内容为堆的性质.python实现插入与删除操作.堆复杂度表.python内置方法生成堆. 区分堆(heap)与栈(stack):堆与二叉树有关,像一堆金字塔型泥沙:而栈像一个直立垃圾桶,一列下 ...

  4. HDU 4352 XHXJ's LIS 数位dp lis

    目录 题目链接 题解 代码 题目链接 HDU 4352 XHXJ's LIS 题解 对于lis求的过程 对一个数列,都可以用nlogn的方法来的到它的一个可行lis 对这个logn的方法求解lis时用 ...

  5. HDU5489 LIS变形

    Removed Interval Problem Description Given a sequence of numbers A=a1,a2,…,aN , a subsequence b1,b2, ...

  6. Shortest and Longest LIS

    Codeforces Round #620 (Div. 2) D. Shortest and Longest LIS 题解: 贪心即可,对于最短序列,我们尽可能用可用的最大数字放入序列中,对于最长序列 ...

  7. 2019HDU多校 Round6

    Solved:2 02 Nonsense Time (LIS) 题意:给定一个全排列 最开始为空的 每秒中一个位置上的数出现 求每秒的LIS 题解:题解说 考虑时光倒流 倒着消掉 因为数据随机 所以期 ...

  8. 【CF486E】LIS of Sequence题解

    [CF486E]LIS of Sequence题解 题目链接 题意: 给你一个长度为n的序列a1,a2,...,an,你需要把这n个元素分成三类:1,2,3: 1:所有的最长上升子序列都不包含这个元素 ...

  9. HDU 4352 XHXJ's LIS HDU 题解

    题目 #define xhxj (Xin Hang senior sister(学姐)) If you do not know xhxj, then carefully reading the ent ...

随机推荐

  1. 零起点学算法09——继续练习简单的输入和计算(a-b)

    #include<stdio.h> int main() { int a,b; scanf("%d %d",&a,&b); printf("% ...

  2. Excel | 如何用Excel实现证件照底色调换

    这段时间因为一些事情需要用到证件照这个东西,大家应该都清楚,不管是简历还是各种考试上面,都需要贴上一张规规矩矩的证件照片或是上传电子照片. 通常,我们到照相馆照证件照的时候,无外乎红底.蓝底以及白底这 ...

  3. Java字符串格式化输入({0}/%s)

    用法: System.out.println(MessageFormat.format("{0}{1}",1,2)); System.out.println(String.form ...

  4. kubernetes HA 脚本

    集群方案: 发行版:CentOS 7 版本: Kubernetes:1.9.1 master高可用方案:keepalived LVS 网络方案:Flannel Master HA 四步骤: 1. 安装 ...

  5. XenApp应用虚拟化介绍

    https://wenku.baidu.com/view/635223c26137ee06eff91864.html

  6. 为什么深度神经网络难以训练Why are deep neural networks hard to train?

    Imagine you're an engineer who has been asked to design a computer from scratch. One day you're work ...

  7. PHP的方法重载实现

    PHP提出面向对象以来,就有着各种各样的问题,其中,不直接支持对象方法重载就是一个让人纠心的问题,在其他语言里面,大可以有以下写法(以下是C++写法): class Abc(){ public fun ...

  8. 【Linux】Shell三类变量的作用域——linux shell “永久环境变量”、“临时环境变量”和"普通变量"之完全解读

      2015-05-08 00:15 3896人阅读 评论(10) 收藏 举报 本文章已收录于:   分类: 软件开发进阶(419) 作者同类文章X Unix/Linux杂项(118) 作者同类文章X ...

  9. JVM组成部分以及内存模型

    一.JVM的组成部分 我们先把JVM这个虚拟机实现机制画出来,例如以下图所看到的: 从这个图中能够看到,JVM是执行在操作系统之上的,它与硬件没有直接的交互. 我们再来看下JVM有哪些组 成部分,例如 ...

  10. 关于js加密解密

    有的时候有些网站的js用简单的eval混淆加密了.解密其实很简单的 解密JS的eval加密码的方式例如这段: 很多朋友以为这段代码是“加密”的,其实这也谈不上是加密,只能算是一种编码(Encode)或 ...