百练oj 2757 最长上升子序列
2015-10-14 20:50
267 查看
2757:最长上升子序列
查看提交
统计
提示
提问
总时间限制: 2000ms 内存限制: 65536kB
描述一个数的序列bi,当b1 < b2 < ... < bS的时候,我们称这个序列是上升的。对于给定的一个序列(a1, a2, ..., aN),我们可以得到一些上升的子序列(ai1, ai2,
..., aiK),这里1 <= i1 < i2 < ... < iK <= N。比如,对于序列(1, 7, 3, 5, 9, 4, 8),有它的一些上升子序列,如(1, 7), (3, 4, 8)等等。这些子序列中最长的长度是4,比如子序列(1, 3, 5, 8).
你的任务,就是对于给定的序列,求出最长上升子序列的长度。
输入输入的第一行是序列的长度N (1 <= N <= 1000)。第二行给出序列中的N个整数,这些整数的取值范围都在0到10000。
输出最长上升子序列的长度。
样例输入
7 1 7 3 5 9 4 8
样例输出
4
来源
翻译自 Northeastern Europe 2002, Far-Eastern Subregion 的比赛试题
ACcode:
#pragma warning(disable:4786)//使命名长度不受限制
#pragma comment(linker, "/STACK:102400000,102400000")//手工开栈
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d%d",&x,&y)
#define rds(x) scanf("%s",x)
#define rdc(x) scanf("%c",&x)
#define ll long long int
#define maxn 1005
#define mod 1000000007
#define INF 0x3f3f3f3f //int 最大值
#define FOR(i,f_start,f_end) for(int i=f_start;i<=f_end;++i)
#define MT(x,i) memset(x,i,sizeof(x))
#define PI acos(-1.0)
#define E exp(1)
using namespace std;
int dp[maxn],a[maxn];
int main(){
int n;
while(rd(n)!=EOF){
FOR(i,1,n){
rd(a[i]);
dp[i]=1;
}
FOR(i,2,n){
FOR(j,1,i-1){
if(a[j]<a[i])
dp[i]=max(dp[i],dp[j]+1);
}
}
cout<<*max_element(dp+1,dp+n+1);
}
return 0;
}
/*
7 1 7 3 5 9 4 8
*/
相关文章推荐
- 我的Java学习之路2——继承中的构造方法
- Oracle多粒度锁机制的总结
- PostgreSQL OID 源码分析
- 点亮一个LED灯
- HTTP响应头信息和请求头信息详解
- lintcode:Product of Array Exclude Itself
- 第七周 项目4-队列数组
- 再战传世推广文本(请复制下面红色字体部分)
- Javascript基础(二)
- Hadoop 文件追加(断点继传)
- Get stream replication state from standby
- Ubuntu14.04桌面版gedit中文乱码解决办法
- UI - SendValue
- 快速熟悉项目代码
- 梯度下降法,最小二乘法求线性回归
- [转]Apache Ignite——新一代数据库缓存系统
- Android SDK - Gradle插件安装方法
- java里面的文件上传与下载
- Handler总结
- 记录学习Python过程中的各种坑