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

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. 【mybatis】mybatis多表联查,存在一对多关系的,实体中使用List作为字段接收查询结果的写法

    实体如下: IntegralGoods  积分商品 IntegralGoodsImg 积分商品图片 ShelfLog 积分商品自动上架记录 IntegralGoods :IntegralGoodsIm ...

  2. 版本控制SVN的使用笔记

    安装 客户端和服务端下载地址,打开网址,根据自己的操作系统下载对应的版本,window用户服务端一般安装的是VisualSVN,客户端安装TortoiseSVN,在实际工作中,我们一般只需要安装Tor ...

  3. RRGGBBAA或者RRGGBB转换成rgba()

    //十六进制颜色值的正则表达式 var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/; /*16进制颜色转为RGB格式*/ var colorRgb = fun ...

  4. war后缀的文件

    其实war文件就是Java中web应用程序的打包.借用一个老兄的话,"当你一个web应用程序很多的时候,如果你想把它部署到别的机器上,来回拷这些文件是件挺郁闷的事情,如果要是一个文件就好了. ...

  5. jQuery.toggleClass() 和detach()方法详解

    一.toggleClass()函数: toggleClass()函数用于切换当前jQuery对象所匹配的每一个元素上指定的css类名.所谓"切换",就是如果该元素上已存在指定的类名 ...

  6. http://blog.sina.com.cn/s/blog_546abd9f0101c6au.html

    http://blog.sina.com.cn/s/blog_546abd9f0101c6au.html

  7. ZOJ3622 Magic Number(水题)

    分析: 举个样例xxx(三位数)为魔力数,则xxx|(xxx+1000*y),那么xxx|1000,这个就是结论 同理:四位数xxxx|10000,五位数xxxxx|100000 代码: #inclu ...

  8. VP9 Video Codec

    http://www.webmproject.org/vp9/ WebM Repositories libvpx: VP8/VP9 Codec SDK   pull http://git.chromi ...

  9. SQL多表连接查询(具体实例)

    本文主要列举两张和三张表来讲述多表连接查询. 新建两张表: 表1:student  截图例如以下: 表2:course  截图例如以下: (此时这样建表仅仅是为了演示连接SQL语句.当然实际开发中我们 ...

  10. vue - 条件语句

    1.与小程序不同之处一,小程序无论变量还是常亮都可以用双向绑定来解决{{}},而vue一旦双(单)引号包起来以后就失效了. 2.注意一点,切记双引号注意不要混淆哈,这里是一排双引号包单引号,那里是一排 ...