POJ 2533 最长递增子序列
2013-11-02 22:37
381 查看
//POJ 2533 n^2 版 #include "stdio.h" #include "queue" #include "math.h" using namespace std; const int maxn = 1005; int n; int num[maxn],d[maxn]; int main() { //freopen("data.in","r",stdin); scanf("%d",&n); for( int i = 1; i <= n; i ++ ) { scanf("%d",&num[i]); } int maxs = 0; for( int i = 1; i <= n; i ++ ) { d[i] = 1; for( int j = 1; j <= i-1; j ++ ) { if( num[j] < num[i] && d[i] < d[j] + 1 ) { d[i] = d[j] + 1; } } if( d[i] > maxs ) maxs = d[i]; } printf("%d\n",maxs); return 0; }
#include <stdio.h> #include <string.h> #include <queue> using namespace std; const int maxn = 1005; int n; int stack[maxn]; int main() { int temp,top = 0; scanf("%d",&n); stack[0] = -1; for( int i = 1; i <= n; i ++ ) { scanf("%d",&temp); if( temp > stack[top] ) stack[++top] = temp; else { int ld = 1, rd = top, mid; while( ld <= rd ) { mid = ( ld+rd )/2; if( temp > stack[mid] ) ld = mid + 1; else rd = mid - 1; } stack[ld] = temp; } } printf("%d\n",top); return 0; }
相关文章推荐
- 信息系统项目管理师考试经验谈 -- 转
- ERP与MES集成技术及其应用研究
- hdu-2317-Nasty Hacks
- 构造方法 静态修饰符
- 设计模式:命令模式(6)C++版
- Linux 目录和文件大小 du
- java反射
- 数据库范式
- java 方法基础
- C#基础笔记——泛型(Genericity)
- Qcon上海第二天参会总结
- &和&&的区别
- 获取Android设备唯一标识
- hdu-1712 分组背包问题
- 线程内核对象对比
- LEX规则
- em px 简单换算
- HTML中 scrollTop++ 不能够实现div向上滚动的原因
- 继承、多态、重载、重写的文字版小总结
- 四款经典html5版网页游戏 在线体验