nlogn 最长上升子序列
2016-02-04 17:38
363 查看
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> #include <cstdlib> using namespace std; const int maxn = 500; const int INF = ~0U >> 1; int a[maxn], d[maxn]; /// a原数据 d[i] 表示长度为i的上升子序列里面最大的那个数 int n; int main() { scanf("%d", &n); for(int i = 0; i < n; ++i) scanf("%d", &a[i]); for(int i = 0; i <= n; ++i) d[i] = INF; int len = 0, x; d[0] = 0; for(int i = 0; i < n; ++i) { if(d[len] < a[i]) x = ++len; else x = lower_bound(d, d + n, a[i]) - d; d[x] = a[i]; } printf("%d\n", len); return 0; }
相关文章推荐
- 分布式系统的CAP定理
- C# enum
- Spring学习8-SSH+Log4j黄金整合
- swift如何实现语言国际化,适应各国语言
- 字符串转换成布尔值
- NOIP解题报告
- Spring学习8-Spring事务管理(注解式声明事务管理)
- 层级查询高级用法, 执行计划hash group by--工作备忘2016/02/02
- Songs
- POJ 1236 Network of Schools(强连通分量)
- Match:Seek the Name, Seek the Fame(POJ 2752)
- Spring学习8-Spring事务管理(AOP/声明式式事务管理)
- mysql-5.7.10普通安装
- Python基础学习笔记(一)环境安装
- 【第一行代码】Android中UI总结
- 贪心算法(二)
- Spring学习8-Spring事务管理(编程式事务管理)
- [POJ 1840]Eqs[hash][枚举]
- 关于Java反射的理解
- ubuntu下sudo命令执行缓慢的解决办法