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

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. 找出最小元素 Exercise07_09

    import java.util.Scanner; /** * @author 冰樱梦 * 时间:2018年下半年 * 题目:找出最小元素 * */ public class Exercise07_0 ...

  2. html5上传图片php特殊处理一下

    $file=$_POST['file']; if($file) { preg_match('|data:image/([a-zA-Z]+);base64,|s',$file,$match); $fil ...

  3. HTML 钟表 小时钟

    该放假了,心情不好,写个小表针感慨一下时间为什么过得如此之快,写了个小钟表. 提示 1:这个钟表的秒针转的非常快,如果需要和当前的网络时间一样,请修改</script>上一行的代码,把1换 ...

  4. php根据汉字获取拼音(php基于拼音搜索实现原理)

    php根据汉字获取拼音(php基于拼音搜索实现原理) 代码一:获取字符串汉字首字母,兼容GBK和UTF-8 <?php function getfirstchar($s0){   //获取单个汉 ...

  5. 在Visual Studio中开发Matlab mex文件,生成mexw64/mexw32

    csunking贡献,2015-9-22 1712 1.   概述 通过使用C/C++与Matlab混合编程,既可以享受到C代码快速执行的速度,又可以方便的使用Matlab众多的库函数和强大的绘图功能 ...

  6. 【maven】ecplise新建maven项目 报错Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resources-plugin

    在ecplise上新建maven项目 报错: Could not calculate build plan: Plugin org.apache.maven.plugins:maven-resourc ...

  7. Visual Studio中 sln 和 suo 文件

    我们通过双击.sln加载出我们的工程,Visual Studio采用两种文件类型(.sln和.suo)来存储解决方案的设置,它们总称为解决方案文件. .sln文件 solution,即解决方案.它引用 ...

  8. 给ul下的li加click时间

    $('.province ul li').click(function() {//方法 });

  9. DB2数据库性能调整和优化(第2版)

    <DB2数据库性能调整和优化(第2版)> 基本信息 作者: 牛新庄 出版社:清华大学出版社 ISBN:9787302325260 上架时间:2013-7-3 出版日期:2013 年7月 开 ...

  10. jquery滚动条插件nanoscroller的应用

    默认的滚动条的样式,各个版本的兼容性不是很好, 推荐一款jQuery 插件nanoscroller ,可以自定义滚动条的样式. 应用: 1.引入样式 nanoscroller.css <link ...