最长上升子序列
来源:互联网 发布:海南大学网络登录入口 编辑:程序博客网 时间:2024/05/29 18:49
#include <iostream>#include<algorithm>#include<string>using namespace std;const int MAX_N = 1010;int a[MAX_N], maxLen[MAX_N];int main(){ int N; cout << "-------------------------" << endl; cout << "输入序列长度:"; cin >> N; cout << "输入序列:" << endl; for (int i = 1; i <= N; ++i){ cin >> a[i]; maxLen[i] = 1; } /* cout << "-------------------------" << endl; // 人人为我递推 for (int i = 2; i <= N;++i) for (int j = 1; j < i; ++j) { if (a[i]>a[j]) maxLen[i] = max(maxLen[i], maxLen[j]+1); } cout <<"最大长度为:"<<* max_element(maxLen + 1, maxLen + N + 1) << endl; cout << "-------------------------" << endl; */ //我为人人递推 for (int i = 1; i <= N;++i) for (int j = i + 1; j <= N; ++j) { if (a[j] > a[i]) maxLen[j] = max(maxLen[j] ,maxLen[i] + 1); } cout << "最大长度为:" << *max_element(maxLen + 1, maxLen + N + 1) << endl; cout << "-------------------------" << endl; return 0;}
阅读全文
0 0
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- 最长上升子序列
- IOS开发要注意数组的赋值问题
- Unicode 和 UTF-8 有何区别?
- linux简介
- 3.4AP_HAL::RCInput and AP_HAL::RCOutput
- PyCharm注册码(破解方法)
- 最长上升子序列
- 自动装箱与对象一致性判断
- 1 面试流程
- kafka初步认识
- HashMap中如果key是自定义的类,为什么重写hashcode()和equals()
- Dijkstra (邻接矩阵的另一种实现)
- 半深入理解CSS3 object-position/object-fit属性
- 《Python基础教程》学习笔记——函数
- Android学习(五)Service学习(下)