经典动态规划之最长上升子序列
来源:互联网 发布:专业网络k歌声卡 编辑:程序博客网 时间:2024/06/07 09:57
/**************************************************** > File Name: lis.cpp > Author: Yuji CAO > Mail: 1007171627@qq.com > Created Time: 五 6/ 2 19:42:39 2017 ****************************************************/#include<map>#include<vector>#include<unordered_set>#include<unordered_map>#include<list>#include<queue>#include<deque>#include<stack>#include<iostream>#include<set>#include<limits>using namespace std;/** * 3 4 2 7 8 4 9 10 11 6 * dp 更新过程 *<3> 3 o o o o o o o o o *<4> 3 4 o o o o o o o o *<2> 2 4 o o o o o o o o *<7> 2 4 7 o o o o o o o *<8> 2 4 7 8 o o o o o o *<4> 2 4 4 8 o o o o o o *<9> 2 4 4 8 9 o o o o o *<10> 2 4 4 8 9 10 o o o o *<11> 2 4 4 8 9 10 11 o o o *<6> 2 4 4 6 9 10 11 o o o */int lis(vector<int>& array) { vector<int> dp(array.size() + 1, numeric_limits<int>::max()); for (int i = 0; i < array.size(); ++i) { auto pos = upper_bound(dp.begin(), dp.end(), array[i]) - dp.begin(); dp[pos] = array[i]; } for (auto ele : dp)cout<<ele<<"\t"; cout<<endl; int end_pos = array.size() - 1; while (end_pos >= 0 && dp[end_pos] == numeric_limits<int>::max()) { end_pos -= 1; } return end_pos + 1;}int main() { int n = 0; cin>>n; vector<int> array; for (int i = 1; i <= n; ++i) { int tmp; cin>>tmp; array.push_back(tmp); } int ans = lis(array); cout<<"answer:\t"<<ans<<endl; return 0;}
阅读全文
0 0
- 经典动态规划之最长上升子序列
- 动态规划之最长上升子序列
- 【动态规划】 之 最长上升子序列
- zoj2136 经典动态规划 求最长上升子序列
- 经典动态规划问题--最长上升子序列 POJ--2533
- 动态规划经典问题 最长上升子序列poj2533
- 动态规划:最长上升子序列之基础(经典算法 n^2)
- poj 1836 (动态规划之最长上升子序列)
- 动态规划(DP)之最长上升子序列
- 动态规划学习之最长上升子序列
- 动态规划(DP)之最长上升子序列问题
- 简单动态规划之最长上升子序列
- C++动态规划算法之最长上升子序列
- 动态规划专题之最长上升子序列
- 算法学习之动态规划--最长上升子序列
- 动态规划:最长上升子序列
- 动态规划-最长上升子序列LIS
- 动态规划求最长上升子序列
- js 基本语法
- WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED解决方法
- 在制定字符串内删除指定字符。
- SpringAOP之注入AspectJ切面
- more than one `-Acdtrux' or `--test-label' option
- 经典动态规划之最长上升子序列
- 使用maven和springMVC项目的结构
- Runtime linking on Mac
- C++ 阻塞队列
- 网络七层模型
- 我的博客
- HDU-1074-状态压缩DP
- The last packet sent successfully to the server was 0 milliseconds ago问题的解决
- 斯特林公式--求阶乘近似值