poj 2533Longest 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
1 7 3 5 9 4 8
Sample Output
4
Source
Northeastern Europe 2002, Far-Eastern Subregion
题解 最长上升子序列,动态规划。
#include<stdio.h>
#include<string.h>
int a[100001];
int dp[100001];
int max(int a,int b)
{
return a>b?a:b;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
memset(dp,0,sizeof(dp));
int res=0;
for(int i=0;i<n;i++)
{
dp[i]=1;
for(int j=0;j<=i;j++)
{
if(a[i]>a[j])
{
dp[i]=max(dp[i],dp[j]+1);
// dp[i]=dp[j]+1;
}
res=max(res,dp[i]);
}
}
printf("%d\n",res);
}
return 0;
}
poj 2533Longest Ordered Subsequence的更多相关文章
- POJ 2533-Longest Ordered Subsequence(DP)
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 34454 Acc ...
- POJ 2533 Longest Ordered Subsequence(LIS模版题)
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 47465 Acc ...
- poj 2533 Longest Ordered Subsequence 最长递增子序列
作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4098562.html 题目链接:poj 2533 Longest Ordered Subse ...
- POJ 2533 - Longest Ordered Subsequence - [最长递增子序列长度][LIS问题]
题目链接:http://poj.org/problem?id=2533 Time Limit: 2000MS Memory Limit: 65536K Description A numeric se ...
- POJ 2533 Longest Ordered Subsequence(裸LIS)
传送门: http://poj.org/problem?id=2533 Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 6 ...
- POJ 2533 Longest Ordered Subsequence(最长上升子序列(NlogN)
传送门 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subseque ...
- POJ 2533 Longest Ordered Subsequence 最长递增序列
Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequenc ...
- poj 2533 Longest Ordered Subsequence(LIS)
Description A numeric sequence of ai is ordered ifa1 <a2 < ... < aN. Let the subsequence of ...
- POJ 2533 Longest Ordered Subsequence(DP 最长上升子序列)
Longest Ordered Subsequence Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 38980 Acc ...
随机推荐
- C#---vs2010发布、打包安装程序程序(转载)
转载地址:点击打开 1. 在vs2010 选择“新建项目”→“ 其他项目类型”→“ Visual Studio Installer→“安装项目”: 命名为:Setup1 . 这是在VS2010中将有三 ...
- 二、React中的更新
创建更新的方式:ReactDOM.render||hydrate 初次渲染,然后是setState.forceUpdate 一.React.render() 步骤:创建ReactRoot.创建Fibe ...
- JS转换日期格式
// 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占 ...
- 软件测试Lab 1 Junit and Eclemma
首先安装eclipse 然后下载hamcrest-core-1.3.jar,下载地址:http://mvnrepository.com/artifact/org.hamcrest/hamcrest-c ...
- Swagger的使用
参考文章: https://blog.csdn.net/xupeng874395012/article/details/68946676/ https://blog.csdn.net/hry2015 ...
- Visual Studio 更改护眼颜色
- 重置SQLSERVER表的自增列,让自增列重新计数【转】
很多时候我们需要重置某个表的自增列,让自增列重新从1开始记数.最蠢的方法当然是把该表删掉再重新建表了.其实,还有其它的方法可以重置自增列的值: 方法一:使用TRUNCATE TABLE语句: TRUN ...
- FTP添加虚拟目录(图)
设置 访问效果 可以看到有这个文件:
- 怎样在github里面写个人主页
1 登录你的账号 打开
- HDU汉诺塔系列
这几天刷了杭电的汉诺塔一套,来写写题解. HDU1207 汉诺塔II HDU1995 汉诺塔V HDU1996 汉诺塔VI HDU1997 汉诺塔VII HDU2064 汉诺塔III HDU2077 ...