Find longest increasing sequence (LIS)
来源:互联网 发布:穷人突破阶级知乎 编辑:程序博客网 时间:2024/05/19 15:19
#include <iostream>#include <stack>typedef unsigned int uint;void FindLIS(const uint arr[], uint length){uint* lis = new uint[length];uint* pre = new uint[length];lis[0] = 0;int max_length = 0;for (int i = 1; i < length; ++i){// find largest j that lis[arr[k]] < arr[i]int k = 0;for (int j = 0; j <= max_length; j++){if (arr[lis[j]] < arr[i])k = j;}pre[i] = lis[k];if (k == max_length || arr[i] < arr[lis[k + 1]]){lis[k + 1] = i;max_length = std::max(max_length, k + 1);}}std::stack<int> stk;int elem_idx = lis[max_length];for (int i = 1; i <= max_length; ++i){int elem = arr[elem_idx];stk.push(elem);elem_idx = pre[elem_idx];}while (!stk.empty()){std::cout << stk.top() << " ";stk.pop();}};int main(){const uint arr[] = {100000, 0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15};uint arr_length = sizeof(arr) / sizeof(arr[0]);FindLIS(arr, arr_length);return 0;}
- Find longest increasing sequence (LIS)
- Longest Increasing Subsequence(LIS)
- Longest Increasing Subsequence(LIS)
- DP-LIS( Longest Increasing Subsequenc)
- Longest Increasing Subsequence,LIS初步
- Longest increasing substring (LIS)--DP
- 最长不降子序列/longest increasing sequence(LIS) O(n*lgn) POJ3670
- [LIS]Longest Increasing Sequence:nlogn算法和两种普通DP的实现
- Leetcode 300 :Longest Increasing Sequence
- Longest Increasing Subsequence (LIS) 的java实现
- DP中的LIS:longest increasing subsequence
- 最长非降子序列LIS(longest increasing subsequence)
- O(n lg n)-time Algorithm to Find the Longest Monotonically Increasing Sub-sequence
- Longest increasing sub sequence poj 1080
- Dynamic Programming之Longest Increasing Subsequence (LIS)问题
- Dynamic Programming之Longest Increasing Subsequence (LIS)问题
- 最长上升子序列 LIS(Longest Increasing Subsequence)
- 最长上升子序列 LIS(Longest Increasing Subsequence)---DP
- 在 Asp.NET MVC 中使用 SignalR 实现推送功能
- Epoll模型
- cin,cout,以及其返回值
- 实现Visual Studio 2010一个很简单的很酷的扩展
- Javascript检测访问的浏览器的操作系统
- Find longest increasing sequence (LIS)
- WPF、WCF、WF打造Hello World程序
- [IPhone] Missing file解决办法
- sizeof与#pragma预编译指令
- windows 下调试ObjectC
- dwr基础:原理,配置,使用,异常
- Android基于XMPP Smack Openfire开发IM(2)登录openfire
- 字节序(Endian),大端(Big-Endian),小端(Little-Endian)
- 跟我一起写Windows JS脚本(二):内置对象与任意COM组件