原文网址:http://www.wretch.cc/blog/celiaailec/18865507
// Q481: What Goes Up // 2008.04.04 Celia // Method: Dynamic Programming (LIS), Backtracking #include // Accepted #define N 100000 #define M 2147483647 int array[N], // array[i]: the ith element of inputptr[N], // ptr[i]: pointer to the previous element in the LIS that end at array[i]last_p[N]; // last_p[i]: pointer to the last element in the LIS of length i int binary_search(int begin_p, int end_p, const int k); void print_result(int p); int main() {int p, i = 0,max_len = 0;array[0] = -M, ptr[0] = 0, last_p[0] = 0;while(scanf("%d", &array[++i]) == 1){p = binary_search(1, max_len+1, array[i]);if(array[i] > array[last_p[p-1]]){if(p > max_len)ptr[i] = last_p[p-1], last_p[p] = i, max_len++;elseif(array[i] <= array[last_p[p]])ptr[i] = last_p[p-1], last_p[p] = i;}}printf("%d/n-/n", max_len);print_result(last_p[max_len]);return 0; } int binary_search(int begin_p, int end_p, const int k) {while(begin_p < end_p){int temp = (begin_p + end_p) / 2;if(array[last_p[temp]] < k)begin_p = temp + 1;elseend_p = temp;}return begin_p; } void print_result(int p) {if(p > 0){print_result(ptr[p]);printf("%d/n", array[p]);} }
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
Duilib中list控件支持ctrl和shif多行选中的实现
[ICML2015]Batch Normalization:Accelerating Deep Network Training by Reducing Internal Covariate Shif
win10系统 微软输入法 于eclipse ctrl+shif+f冲突间接处理办法
Codeforces Round #259 (Div. 2) B. Little Pony and Sort by Shif
读LDD3,内存映射与DMA--PAGE_SHIF…
VMware虚拟机安装XP【要先分区,再设置BOOT 启动CD,shif+上移】
更换iBus五笔的左与右Shif
sublime ctrl+shif+f 没用解决办法
idea 对 ctrl + z 的撤销 是 ctrl + shif + z
计算机最早的设计师应用于,计算机应用基础选择题doc.doc
win10自带截图神器:Win+Shift+S
Python基础之文件目录操作
python简述目录_Python基础之文件目录操作(示例代码)
tp5 如何做数据采集
任务2-7(服务器字体+阿里巴巴矢量库)
html标签(1):h1~h6,p,br,pre,hr
TI 电量计介绍与芯片选型指南
几款TI电源芯片简介
TI DSP芯片C2000系列读取FLASH数据
德州仪器(Ti)平台嵌入式开发基础
TI三相电机智能栅极驱动芯片特点分类
省选模拟(12.08) T3 圈圈圈圈圈圈圈圈
Hadoop生态圈技术栈(上)
大数据开发基础入门与项目实战(三)Hadoop核心及生态圈技术栈之6.Impala交互式查询
小猿圈之Linux下Mysql 操作命令
大数据Hadoop生态圈常用面试题
大数据开发基础入门与项目实战(三)Hadoop核心及生态圈技术栈之4.Hive DDL、DQL和数据操作
备战Noip2018模拟赛11(B组)T3 Monogatari 物语
【智能优化算法-圆圈搜索算法】基于圆圈搜索算法Circle Search Algorithm求解单目标优化问题附matlab代码
NYOJ 78 圈水池
递归问题 跑道 汽车 绕圈问题 Python实现
Hadoop生态圈(三):MapReduce
微信公众账号
微信扫一扫加关注