Heap 3214 LIS题解
依据问题转换成最长不降子序列问题。
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题解的更多相关文章
- HDU4352 XHXJ's LIS 题解 数位DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4352 题目大意: 求区间 \([L,R]\) 范围内最长上升子序列(Longest increasin ...
- BZOJ3173:[TJOI2013]最长上升子序列 & HDU3564:Another LIS——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=3173 http://acm.hdu.edu.cn/showproblem.php?pid=3564 ...
- python数据结构之堆(heap)
本篇学习内容为堆的性质.python实现插入与删除操作.堆复杂度表.python内置方法生成堆. 区分堆(heap)与栈(stack):堆与二叉树有关,像一堆金字塔型泥沙:而栈像一个直立垃圾桶,一列下 ...
- HDU 4352 XHXJ's LIS 数位dp lis
目录 题目链接 题解 代码 题目链接 HDU 4352 XHXJ's LIS 题解 对于lis求的过程 对一个数列,都可以用nlogn的方法来的到它的一个可行lis 对这个logn的方法求解lis时用 ...
- HDU5489 LIS变形
Removed Interval Problem Description Given a sequence of numbers A=a1,a2,…,aN , a subsequence b1,b2, ...
- Shortest and Longest LIS
Codeforces Round #620 (Div. 2) D. Shortest and Longest LIS 题解: 贪心即可,对于最短序列,我们尽可能用可用的最大数字放入序列中,对于最长序列 ...
- 2019HDU多校 Round6
Solved:2 02 Nonsense Time (LIS) 题意:给定一个全排列 最开始为空的 每秒中一个位置上的数出现 求每秒的LIS 题解:题解说 考虑时光倒流 倒着消掉 因为数据随机 所以期 ...
- 【CF486E】LIS of Sequence题解
[CF486E]LIS of Sequence题解 题目链接 题意: 给你一个长度为n的序列a1,a2,...,an,你需要把这n个元素分成三类:1,2,3: 1:所有的最长上升子序列都不包含这个元素 ...
- HDU 4352 XHXJ's LIS HDU 题解
题目 #define xhxj (Xin Hang senior sister(学姐)) If you do not know xhxj, then carefully reading the ent ...
随机推荐
- Java学习笔记(13)
StringBuffer 增加 append(boolean b) 可以添加任意类型的数据到容器中 insert(int offset,boolean b) 指定插入的索引值,插入对应的内容 ...
- mybatis异常: invalid comparison: java.util.ArrayList and java.lang.String] with root cause
mybatis中使用动态sql,报错: invalid comparison: java.util.ArrayList and java.lang.String] with root cause 是由 ...
- React的思想
react是什么 react是开发出来用来促进UI交互的,创建带有状态的.可复用的UI组件的IU库 react不仅可以在浏览器端使用,还可以在服务器端使用,还可以两端一起使用. react的底层概念: ...
- 将json字符串转换成list<T>
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Se ...
- OpenVPN记住账号密码自动连接
说明:在增加了证书+账号密码之后,安全性确实提高了,但是面临的问题也有,每次重启时必须输入账号密码才能连接,这也造成了无人值守的问题. 解决: 1.在Client的client.ovpn末尾添加一行a ...
- 使用MailKit收发邮件
.Net BCL库中对于邮件的支持只有SmtpClient一个,它只能进行简单的邮件的发送操作,并且不支持POP3和SMTP,无法接收邮件,用起来有诸多不便. 今天看到园子里有文章(使用 MimeKi ...
- (获取选中的光标起始位置)EditText常用属性【三】:EditText选取操作
转自:http://blog.csdn.net/wirelessqa/article/details/8567702 话不多说,直接上码: activity_main.xml <ScrollVi ...
- phpok -- 域名问题
nginx会改变连接的baseurl, 所以要改变nginx的server name的配置. 将网站改为静态也需配置nginx.
- Android进阶笔记:AIDL内部实现详解 (一)
AIDL内部实现详解 (一) AIDL的作用是实现跨进程通讯使用方法也非常的简单,他的设计模式是典型的C/S架构.使用AIDL只要在Client端和Server端的项目根目录下面创建一个aidl的文件 ...
- (转载)如何学好iphone游戏开发
转自:http://www.cnblogs.com/zilongshanren/archive/2011/09/19/2181558.html 自从发布<如何学习iphone游戏开发>到 ...