POJ2533 Longest ordered subsequence
Longest Ordered Subsequence
Description A numeric sequence of ai is ordered if a1 < 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 Sample Output 4 Source Northeastern Europe 2002, Far-Eastern Subregion
|
[Submit] [Go Back] [Status] [Discuss]
#include<cstdio>
#include<iostream>
using namespace std; int main()
{
int n, a[], cn = , Maxlenth[], M = ;
cin >> n;
for(int i = ; i < n; i++) {
cin >> a[i];
Maxlenth[i] = ;
}
for(int i = n - ; i >= ; i--) {
for(int j = i + ; j < n; j++) {
if(a[i] < a[j] && Maxlenth[i] <= Maxlenth[j]) Maxlenth[i] = + Maxlenth[j];
if(Maxlenth[i] > M) M = Maxlenth[i];
}
}
cout << M << endl;
return ;
}
POJ2533 Longest ordered subsequence的更多相关文章
- POJ2533——Longest Ordered Subsequence(简单的DP)
Longest Ordered Subsequence DescriptionA numeric sequence of ai is ordered if a1 < a2 < ... &l ...
- POJ2533 Longest Ordered Subsequence 【最长递增子序列】
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 32192 Acc ...
- (线性DP LIS)POJ2533 Longest Ordered Subsequence
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 66763 Acc ...
- poj-2533 longest ordered subsequence(动态规划)
Time limit2000 ms Memory limit65536 kB A numeric sequence of ai is ordered if a1 < a2 < ... &l ...
- POJ2533 Longest Ordered Subsequence —— DP 最长上升子序列(LIS)
题目链接:http://poj.org/problem?id=2533 Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 6 ...
- [POJ2533]Longest Ordered Subsequence<dp>
题目链接:http://poj.org/problem?id=2533 描述: A numeric sequence of ai is ordered if a1 < a2 < ... & ...
- POJ-2533.Longest Ordered Subsequence (LIS模版题)
本题大意:和LIS一样 本题思路:用dp[ i ]保存前 i 个数中的最长递增序列的长度,则可以得出状态转移方程dp[ i ] = max(dp[ j ] + 1)(j < i) 参考代码: # ...
- POJ2533 Longest Ordered Subsequence (线性DP)
设dp[i]表示以i结尾的最长上升子序列的长度. dp[i]=max(dp[i],dp[j]+1). 1 #include <map> 2 #include <set> 3 # ...
- POJ2533:Longest Ordered Subsequence(LIS)
Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence ...
随机推荐
- C#读取Word文档内容代码
首先要添加引用com组件:然后引用: using Word = Microsoft.Office.Interop.Word; 获取内容: /// /// 读取 word文档 返回内容 /// //// ...
- win7 打开方式不能添加程序
打开注册表,找到“HKEY_CLASSES_ROOT\Applications\”中,查看相应的程序的“\shell\open\command”项中的数据是否正确:如果不正确,就修改正确,之后再添加程 ...
- Android中px、dp、sp的区别
px: 即像素,1px代表屏幕上一个物理的像素点: px单位不被建议使用,因为同样100px的图片,在不同手机上显示的实际大小可能不同,如下图所示(图片来自android developer guid ...
- VB php JAVA关于数据库连接数过多的解决方法
这里讲解一个关于数据库连接多多的解决办法 一般都会在方法中进行数据库的开,利用和关 不过如果在一个循环里面使用的时候 这样数据库的连接数就会过多,如果是1万次的话,数据库服务器可能就会当机 PHP 中 ...
- Hql 执行CRUD
//新增] @Test public void add(){ config = new Configuration(); sessionfactory = config.configure(" ...
- C# Wpf双向绑定实例
Wpf中双向绑定处理需要两处 实例1: 1.前台Xaml中属性Binding 时Model指定 TwoWay <Grid> <Ellipse x:Name="ellipse ...
- Smarty的配置与高级缓存技术
转之--http://www.cnblogs.com/-run/archive/2012/06/04/2532801.html Smarty 是一个出色的PHP模板引擎,它分离了逻辑代码和user i ...
- Sql Server使用技巧
1.修改表的字段时,提示不能更改: 工具>选项>设计器>取消 阻止保存要求重新创建表的更改 2.更改选择多少行,编辑多少行: 工具>选项>Sql Server对象资源管理 ...
- onresize的定义方式
1.直接在html中定义如<body onresize="doResize()"/> 2.直接给onresize赋值给window和body的onresize赋值如wi ...
- thinkphp对文件的上传,删除,下载操作
工作需要,整理一下最近对php的学习经验,希望能对自己有帮助或者能帮助那些需要帮助的人. thinkphp对文件的操作,相对来说比较简单,因为tp封装好了一个上传类Upload.class.php 废 ...