uva10534 hdu2198 双向LIS问题
LIS问题算是DP中很基础很简单的一类问题,其经典算法时间复杂度为O(n^2);利用它本身的特点,结合二分法,即可设计出时间复杂度为O(n*log n)的优化算法。LIS的变形好像不太多,下面是两个很相似的双向LIS问题,其实第二个题的代码是直接用第一个题的代码改的。
uva10543:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=17&page=show_problem&problem=1475
Problem D
Wavio Sequence
Input: Standard Input
Output: Standard Output
Time Limit: 2 Seconds
Wavio is a sequence of integers. It has some interesting properties.
· Wavio is of odd length i.e. L = 2*n + 1.
· The first (n+1) integers of Wavio sequence makes a strictly increasing sequence.
· The last (n+1) integers of Wavio sequence makes a strictly decreasing sequence.
· No two adjacent integers are same in a Wavio sequence.
For example 1, 2, 3, 4, 5, 4, 3, 2, 0 is an Wavio sequence of length 9. But 1, 2, 3, 4, 5, 4, 3, 2, 2 is not a valid wavio sequence. In this problem, you will be given a sequence of integers. You have to find out the length of the longest Wavio sequence which is a subsequence of the given sequence. Consider, the given sequence as :
1 2 3 2 1 2 3 4 3 2 1 5 4 1 2 3 2 2 1.
Here the longest Wavio sequence is : 1 2 3 4 5 4 3 2 1. So, the output will be 9.
Input
The input file contains less than 75 test cases. The description of each test case is given below: Input is terminated by end of file.
Each set starts with a postive integer, N(1<=N<=10000). In next few lines there will be N integers.
Output
For each set of input print the length of longest wavio sequence in a line.
Sample Input Output for Sample Input
10 1 2 3 4 5 4 3 2 1 10 19 1 2 3 2 1 2 3 4 3 2 1 5 4 1 2 3 2 2 1 5 1 2 3 4 5 |
9 9 1 |
#include <cstdio>
#include <algorithm>
using namespace std;
int LIS[10010];
int LDS[10010];
int minlis[10010];
int data[10010];
int binary(int l, int r , int x){int mid; while(l <= r){mid = (l + r) >> 1; if(minlis[mid] < x) l = mid + 1; else r = mid -1;} return l;
}
int main(){int n, maxn, len;while(~scanf("%d", &n)){for(int i = 1; i <= n; i++) scanf("%d", data + i); minlis[1] = data[1]; LIS[1] = 1; len = 1;for(int i = 2; i <= n; i++){LIS[i] = binary(1, len, data[i]); minlis[LIS[i]] = data[i]; if(LIS[i] > len) len++;}minlis[1] = data[n]; LDS[n] = 1; len = 1;for(int i = n-1; i > 0; i--){LDS[i] = binary(1, len, data[i]); minlis[LDS[i]] = data[i]; if(LDS[i] > len) len++;}maxn = 0;for(int i = 1; i <= n; i++)maxn = max(maxn , 2 * min(LIS[i] , LDS[i]) - 1); printf("%d\n", maxn);}return 0;
}
How many elements you must throw out?
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 383 Accepted Submission(s): 152
![](http://acm.hdu.edu.cn/data/images/C128-1007-1.jpg)
You are given a sequence of numbers. Output the minimal number of elements you must throw out from the given sequence such that the remaining subsequence satisfies the condition described above.
#include <cstdio>
#define max(a , b) ((a) > (b) ? (a) : (b))
int LIS[55];
int LDS[55];
long long minlis[55];
long long data[55];
int binary(int l, int r , int x){int mid; while(l <= r){mid = (l + r) >> 1;if(minlis[mid] < x) l = mid + 1; else r = mid -1;} return l;
}
int main(){int n, maxn, len;while(~scanf("%d", &n) && n != 0){for(int i = 1; i <= n; i++) scanf("%lld", data + i); minlis[1] = data[1]; LIS[1] = 1; len = 1;for(int i = 2; i <= n; i++){LIS[i] = binary(1, len, data[i]); minlis[LIS[i]] = data[i]; if(LIS[i] > len) len++;}minlis[1] = data[n]; LDS[n] = 1; len = 1;for(int i = n-1; i > 0; i--){LDS[i] = binary(1, len, data[i]); minlis[LDS[i]] = data[i]; if(LDS[i] > len) len++;}maxn = 0;for(int i = 1; i <= n; i++)maxn = max(maxn , LIS[i] + LDS[i] - 1); printf("%d\n", n - maxn);}return 0;
}
uva10534 hdu2198 双向LIS问题相关推荐
- UVA10534 Wavio Sequence【LIS+DP】
Wavio is a sequence of integers. It has some interesting properties. • Wavio is of odd length i.e. L ...
- this指向、数据双向流、传递参数、JSX中循环、React中样式、路由、引入资源的其它方式、create-react-app脚手架、事件处理、获取数据、UI框架推荐、pc桌面应用electronjs
改变this指向的几种方式: //1.使用箭头函数代替原始函数写法:getState=()=>{}//2.在函数调用时给函数名加bind(this)方法:(bind中第一个参数表示修改this指 ...
- 区域云LIS检验系统源码 商业级LIS全套源代码 预留标准HIS、仪器数据接入接口
商业级高端云LIS系统源码,可直接上手项目,正版授权. 系统概述: 系统完全采用B/S架构模式,扩展性强.整个系统的运行基于WEB层面,只需要在对应的工作台安装一个浏览器软件有外网即可访问. 私信我了 ...
- Vue.js 基础语法 入门语句 Vue学习笔记 v-model 双向数据绑定
Vue.js 基础语法,入门语句,Vue学习笔记 学习网站:https://www.bilibili.com/video/BV15741177Eh vue 的体验 响应式:数据一旦改变,视图就会响应改 ...
- lis通道号_LIS系统功能模块和技术参数
1 南华县中医院 LIS 系统功能模块和技术参数 检验申请系统: 1. 通过和 HIS 建立无缝连接,可以直接读取 HIS 中的检验申请单. 2. 支持各工作站录入申请单. 3. 可打印检验申请单 ...
- lis双工常见设置!
LIS仪器双工手册 LIS仪器双工手册 1 化学发光Bayer Centaur 1 化学发光 罗氏 Roche ES2010 2 化学发光 罗氏E411 2 生化仪 奥林巴斯 AU400 2 生化仪 ...
- LIS系统通讯程序原理与实现
一.BSLIS仪器数据采集方法 BSLIS对检验仪器的数据采集主要通过串行口通讯.USB端口通讯.TCP/IP通讯.定时监控数据库和手工录入等几种方法.串行口通讯最为普遍,采用RS-232C标准,一般 ...
- 医院检验管理系统lis系统源码
子系统 功能模块 功能描述 检验 医生 工作 平台 检验 录入 处理 模块 界面集成录入.审核.报告.打印.质控图功能.一个界面能完成大部分检验等相关工作.方便使用. 提供自定义病人资料显示列,审核和 ...
- 医院LIS系统解决方案
要求检验项目直接从 LIS 系统发送到检验设备 (同时发送标本编号与仪器架号相对应) , 仪器结果出来后又会以同样的对应号发送回 LIS 上,就不需要读取条形码也不存在输错项目 或漏检项目的问题,对于 ...
最新文章
- R语言使用lmPerm包应用于线性模型的置换方法(置换检验、permutation tests)、使用lm模型构建简单线性回归模型、使用lmp函数生成置换检验回归分析模型
- 项目中用到的三个绿色自动备份方法
- LeetCode Reverse Linked List II 反置链表2
- B15_NumPy 矩阵库(Matrix)(empty(),zeros(),ones(),eye(),identity(),rand())
- django html显示xml,如何将HTML与Django集成?
- 13新功能_新功能简介|MySQL8.0数据查询脱敏
- 常用浏览器修改User-Agent的方法
- 如何听节拍器_如何用节拍器卡节拍?节拍器的使用方法!
- 网络故障处理手册大全
- ptime在SIP中的应用
- mysql数据库定时清理数据
- 名字作诗(藏头名字作诗)
- JQ实现多checkbox选一清其它
- python画小树_如何用Python画一颗小树?
- 靶向药物丨艾美捷西妥昔单抗Cetuximab方案
- Vue3.0----综合案例(第七章)
- 孩子不是绑架婚姻的借口
- 关于工资、社保、公积金、个人所得税等小常识
- 基于 WebRTC 的 P2P 文件传输
- 使用TCPDF插件生成pdf以及pdf的中文处理
热门文章
- ECCV2020Workshop-PAN-270k参数量SISR网络 | Efficient Image Super-Resolution Using Pixel Attention
- 量产pny的USB3.0-金棒U盘
- 基于51单片机的万年历(算法实现)
- 论文中写伪代码的工具
- Psychtoolbox刺激呈现方式
- R语言 - 集成开发环境IDE
- 河南大学计算机考研群2021,河南大学2021年统考生拟录取名单公示
- 360手机:360N5 Twrp、Root、Magisk教程
- 物流科技杂志物流科技杂志社物流科技编辑部2022年第11期目录
- 【装修选材】自然系原木,才是空间真正的百搭之王!