CSUOJ 1551 Longest Increasing Subsequence Again
1551: Longest Increasing Subsequence Again
Time Limit: 2 Sec Memory Limit: 256 MB
Submit: 75 Solved: 52
Description
Give you a numeric sequence. If you can demolish arbitrary amount of numbers, what is the length of the longest increasing sequence, which is made up of consecutive numbers? It sounds like Longest Increasing Subsequence at first sight. So, there is another limitation: the numbers you deleted must be consecutive.
Input
There are several test cases.
For each test case, the first line of input contains the length of sequence N(1≤N≤10^4). The second line contains the elements of sequence——N positive integers not larger than 10^4.
Output
For each the case, output one integer per line, denoting the length of the longest increasing sequence of consecutive numbers, which is achievable by demolishing some(may be zero) consecutive numbers.
Sample Input
7
1 7 3 5 9 4 8
6
2 3 100 4 4 5
Sample Output
4
4
HINT
Source
解题:线段树。。
#include <bits/stdc++.h>
using namespace std;
const int maxn = ;
struct node{
int lt,rt,value;
}tree[maxn<<];
struct Block {
int lt,rt;
} block[maxn];
void build(int lt,int rt,int v) {
tree[v].lt = lt;
tree[v].rt = rt;
tree[v].value = ;
if(lt == rt) return;
int mid = (lt + rt)>>;
build(lt,mid,v<<);
build(mid+,rt,v<<|);
}
int query(int id,int v) {
if(tree[v].lt == tree[v].rt) return ;
int mid = (tree[v].lt + tree[v].rt)>>;
if(id <= mid) return max(query(id,v<<),tree[v<<|].value);
return query(id,v<<|);
}
void update(int id,int v,int value) {
int mid = (tree[v].lt + tree[v].rt)>>;
tree[v].value = max(tree[v].value,value);
if(tree[v].lt == tree[v].rt) return;
if(id <= mid) update(id,v<<,value);
else update(id,v<<|,value);
}
int n,m,d[maxn],discrete[maxn],width[maxn];
int main() {
while(~scanf("%d",&n)) {
for(int i = m = ; i < n; ++i) {
scanf("%d",d+i);
discrete[i] = d[i];
}
sort(discrete,discrete+n);
int len = unique(discrete,discrete+n) - discrete;
build(,len-,);
block[m].lt = block[m].rt = ;
for(int i = ; i < n; ++i)
if(d[i-] < d[i]) block[m].rt++;
else {
++m;
block[m].lt = block[m].rt=i;
}
for(int i = ; i <= m; ++i)
for(int j = block[i].rt; j >= block[i].lt; --j)
width[j] = block[i].rt-j+;
int ans = ;
for(int i = m; i >= ; --i) {
for(int j = block[i].rt; j >= block[i].lt; --j) {
int id = lower_bound(discrete,discrete+len,d[j])-discrete;
ans = max(j - block[i].lt + + query(id,),ans);
update(id,,width[j]);
}
}
printf("%d\n",ans);
}
return ;
}
CSUOJ 1551 Longest Increasing Subsequence Again的更多相关文章
- CSU - 1551 Longest Increasing Subsequence Again —— 线段树/树状数组 + 前缀和&后缀和
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1551 题意: 给出一段序列, 删除其中一段连续的子序列(或者不删), 使得剩下的序列 ...
- CSU 1551 Longest Increasing Subsequence Again(树状数组 或者 LIS变形)
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1551 升级版:Uva 1471 题意: 让你求删除一段连续的子序列之后的LIS. 题 ...
- csu 1551: Longest Increasing Subsequence Again BIT + 思维
预处理last[i]表示以第i个开始,的合法后缀. pre[i]表示以第i个结尾,的合法前缀. 那么每一个数a[i],肯定是一个合法后缀last[i] + 一个合法前缀,那么合法前缀的数字要小于a[i ...
- [LeetCode] Longest Increasing Subsequence 最长递增子序列
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...
- [tem]Longest Increasing Subsequence(LIS)
Longest Increasing Subsequence(LIS) 一个美丽的名字 非常经典的线性结构dp [朴素]:O(n^2) d(i)=max{0,d(j) :j<i&& ...
- [LintCode] Longest Increasing Subsequence 最长递增子序列
Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return ...
- Leetcode 300 Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...
- [LeetCode] Longest Increasing Subsequence
Longest Increasing Subsequence Given an unsorted array of integers, find the length of longest incre ...
- The Longest Increasing Subsequence (LIS)
传送门 The task is to find the length of the longest subsequence in a given array of integers such that ...
随机推荐
- iOS RegexKitLite 提取匹配的内容
使用RegexKitLite正则表达式需要以下工作: 1.RegexKitLite官方网址(内含使用教程):http://regexkit.sourceforge.net/RegexK ...
- SQLSever: 怎样在select中的每一行产生不同的随机数?
select 的随机函数有点假, 或许是由于它是基于时间来的吧, 同一select中由于时间无法错开导致产生的随机数都是一样的. 怎样做到让不同的行拥有不同的随机数呢? 以下以产生某个月的随机日期来演 ...
- 利用Matlab自带的深度学习工具进行车辆区域检测与车型识别【Github更新!!!】(三)
前言 对前面的东西更新了一下.地方包括: 1.GUI的更新,更友好的用户界面 2.支持用手直接画车辆区域,并且识别出来 3.将proposal.detect.fine-grained classifi ...
- 19.允许重复的unordered_map
#include <string> #include <iostream> //查询性能最高 //允许重复的,hash_map #include <unordered_m ...
- 【DNN控件】
<dnn:DNNDataGrid ID="show" runat="server" DataSourceID="ObjectDataSource ...
- 5、Go if else 条件判断
package main import "fmt" func main(){ //注:在Go里面没有三元表达式”?:”,所以你只能使用条件判断语句. //示例一 if 7%2==0 ...
- ResNet(深度残差网络)
注:平原改为简单堆叠网络 一般x是恒等映射,当x与fx尺寸不同的时候,w作用就是将x变成和fx尺寸相同. 过程: 先用w将x进行恒等映射.扩维映射或者降维映射d得到wx.(没有参数,不需要优化器训练) ...
- python IO编程-序列化
原文链接:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/00143192607 ...
- DICOM:Transfer Syntax传输语义之奇葩GE Private TS
背景: 专栏之前对Transfer Syntax(暂定中文翻译为传输语义,8月初博客中提到的DICOM3.0标准中文版开源书籍计划顺利启动.兴许会面临诸多专有名词的翻译工作,欢迎广大博友提意见)进行过 ...
- LINUX 系统初始化脚本
#!/bin/bash ######the system first start configuretion #####for install ####copy right by donglei## ...