UVa1471
保留有价值的数字的做法,实际上这道题因为n只有1e5,所以不需要这种优化。
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
const int maxn=;
using namespace std;
int t;
int n;
struct node{
int val;
int dpl,dpr;
bool operator < (const node &rhs) const{
if(val == rhs.val)
return dpl < rhs.dpl;
else return val < rhs.val;
}
}a[maxn+];
set<node> s;
void init(){
s.clear();
memset(a, , sizeof(a));
scanf("%d",&n);
for(int i = ; i <= n; ++i){
scanf("%d", &a[i].val);
}
for(int i = n; i >= ; --i){
if(a[i].val < a[i+].val){
a[i].dpr = a[i+].dpr + ;
} else{
a[i].dpr = ;
}
}
}
int solve(){
int res = ;
for(int i = ; i <= n; ++i){
if(a[i].val > a[i-].val){
a[i].dpl = a[i-].dpl + ;
} else {
a[i].dpl = ;
}
set<node>::iterator it1 = s.lower_bound(a[i]);
if(it1 != s.begin()){
--it1;
res = max(res, (*it1).dpl + a[i].dpr);
} else res = max(res, a[i].dpr);
if(i == ){
s.insert(a[i]);
continue;
}
set<node>::iterator it = s.lower_bound(a[i]);
set<node>::iterator temp = it;
if(it != s.begin()){
--it;
if((*it).dpl >= (a[i]).dpl){
continue;
}
}
it = temp;
while(it != s.end()){
if((*it).dpl <= a[i].dpl){
it = s.erase(it);
} else {
break;
}
}
s.insert(a[i]);
}
return res;
}
int main()
{
scanf("%d",&t);
while(t--){
init();
int ans = solve();
printf("%d\n", ans);
}
return ;
}
UVa1471的更多相关文章
- UVA1471( LIS变形)
这是LIS的变形,题意是求一个序列中去掉某个连续的序列后,能得到的最长连续递增序列的长度. 用DP的解法是:吧这个序列用数组a来记录,再分别用两个数组f记录以i结尾的最长连续递增序列的长度,g[i]记 ...
- uva1471 二叉搜索树
此题紫书上面有详细分析,关键是运用Set优化实现O(nlgn)复杂度 AC代码: #include<cstdio> #include<set> #include<algo ...
- 8-8 Ddfense Line uva1471 优先级队列
题意:给你一串长度为n的序列 你的任务是删除一个连续的子序列 使得剩下的序列中有一个长度最大的连续递增子序列 例如 将 5 3 4 9 2 8 6 7 1 中的9 2 8 删除 得到5 3 ...
- 二分 连续上升子序列变形 UVA1471
最大上升子序列解法: 1.动规转移方程 2.(nlogn) #include<cstdio> #include<algorithm> using namespace std; ...
- UVa 1471 防线
https://vjudge.net/problem/UVA-1471 题意:给出一个序列,删除一个连续子序列,使得剩下的序列中有一个长度最大的连续递增子序列,输出个数. 思路:首先可以计算出以i结尾 ...
- 【二分】Defense Lines
[UVa1471] Defense Lines 算法入门经典第8章8-8 (P242) 题目大意:将一个序列删去一个连续子序列,问最长的严格上升子序列 (N<=200000) 试题分析:算法1: ...
随机推荐
- 织梦简洁机械设备dedecms模板
织梦简洁机械设备dedecms模板,个人网站模板,dedecms模板. 模板地址:http://www.huiyi8.com/sc/7269.html
- BZOJ 1634 [Usaco2007 Jan]Protecting the Flowers 护花:贪心【局部分析法】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1634 题意: 约翰留下他的N只奶牛上山采木.可是,当他回来的时候,他看到了一幕惨剧:牛们正 ...
- 分享知识-快乐自己:什么是MVC
1.什么是mvc: Model View Controller,是模型-视图-控制器的缩写,一种软件设计典范,用一种业务逻辑.数据.界面显示分离的方法组织代码,将业务逻辑聚集到一个组件里,在改进和个性 ...
- python-函数用法
Python 一.lower() 方法转换字符串中所有大写字符为小写. lower()方法语法: str.lower() 参数 无. 返回值 返回将字符串中所有大写字符转换为小写后生成的字符串. 练习 ...
- SpringBoot_Exception_01_No plugin found for prefix 'spring-boto' in the current project
一.异常现象 spingbott项目在eclipse中执行maven命令:spring-boot:run, 出现异常: No plugin found for prefix 'spring-boto' ...
- Git_学习_02_ 分支
Git鼓励大量使用分支: 1.查看分支:git branch 2.创建分支:git branch <name> 3.切换分支:git checkout <name> 4.创建+ ...
- Eclipse_插件_02_jd-eclipse插件的安装
1.去官网下载 jd-eclipse插件 2.解压后的文件夹A放到eclipse的drops文件夹下 3.删掉多余文件,确保文件夹A下只有plugin 和 freature 两个文件夹 4.清空osg ...
- Apache-POI 简单应用
测试的Excel文件为四列的普通表格 jar包:poi-3.15-beta2.jar(Office2003xls文件).poi-ooxml-3.15-beta2.jar(Office2007xlsx文 ...
- ls命令还能这么玩
排序文件大小: 我们希望以文件大小排序,我们可以使用-S 参数来这么做 如果希望文件大小从小到大排序: 如果只希望列出目录条目: 增加 /(斜线) 标记目录:要这么做,使用-p选项: 通过修改时间列出 ...
- RT-Thread信号量使用(动态/静态信号量) 及 信号量的四种使用场合
信号量(Semaphore),有时被称为信号灯,是在多线程环境下使用的一种设施,是可以用来保证两个或多个关键代码段不被并发调用.在进入一个关键代码段之前,线程必须获取一个信号量:一旦该关键代码段完成了 ...