POJ2533:Longest Ordered Subsequence(LIS)
2016-07-24 14:29
369 查看
Description
A numeric sequence of ai is ordered ifa1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1,a2, ..., aN)
be any sequence (ai1,ai2, ..., aiK), where 1 <=i1 < i2 < ... < iK <=N. For example, sequence (1,
7, 3, 5, 9, 4, 8) has ordered subsequences, e. g., (1, 7), (3, 4, 8) and many others. All longest ordered subsequences are of length 4, e. g., (1, 3, 5, 8).
Your program, when given the numeric sequence, must find the length of its longest ordered subsequence.
Input
The first line of input file contains the length of sequence N. The second line contains the elements of sequence - N integers in the range from 0 to 10000 each, separated by spaces. 1 <= N <= 1000
Output
Output file must contain a single integer - the length of the longest ordered subsequence of the given sequence.
Sample Input
Sample Output
4
A numeric sequence of ai is ordered ifa1 < a2 < ... < aN. Let the subsequence of the given numeric sequence (a1,a2, ..., aN)
be any sequence (ai1,ai2, ..., aiK), where 1 <=i1 < i2 < ... < iK <=N. For example, sequence (1,
7, 3, 5, 9, 4, 8) has ordered subsequences, e. g., (1, 7), (3, 4, 8) and many others. All longest ordered subsequences are of length 4, e. g., (1, 3, 5, 8).
Your program, when given the numeric sequence, must find the length of its longest ordered subsequence.
Input
The first line of input file contains the length of sequence N. The second line contains the elements of sequence - N integers in the range from 0 to 10000 each, separated by spaces. 1 <= N <= 1000
Output
Output file must contain a single integer - the length of the longest ordered subsequence of the given sequence.
Sample Input
7 1 7 3 5 9 4 8
Sample Output
4
#include<cstdio> #include<iostream> #include<algorithm> #define N 1100 using namespace std; int a ,dp ; int main() { int n,i,j,maxx; maxx=1; cin>>n; for(i=1;i<=n;i++) { cin>>a[i]; dp[i]=1; } for(i=1;i<=n;i++) { for(j=1;j<i;j++) if(a[j]<a[i]) dp[i]=max(dp[i],dp[j]+1); maxx=max(dp[i],maxx); } cout<<maxx<<endl; return 0; }
相关文章推荐
- 详解Android应用中屏幕尺寸的获取及dp和px值的转换
- 基于Android中dp和px之间进行转换的实现代码
- Android中dip、dp、sp、pt和px的区别详解
- 简单的四则运算
- 数的奇偶性
- ACMer博客瀑布流分析
- LFC1.0.0 版本发布
- ACM程序设计大赛题目分类
- 2015年acm国内排名
- Android dpi,dip,dp的概念以及屏幕适配
- 计算字符串最后一个单词长度
- Android px、dp、sp之间相互转换
- ACM网址
- 1272 小希的迷宫
- 1272 小希的迷宫
- hdu 1250 大数相加并用数组储存
- HP data protector软件学习1--基本角色与基本工作流程
- HP data protector软件学习2--软件组成与界面介绍
- 矩阵的乘法操作
- android中像素单位dp、px、pt、sp的比较