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 ...
随机推荐
- Java语言程序设计(第三版)第二章课后习题答案(仅供参考)
2.1 注意不同类型转换 import java.util.Scanner; public class Ch02 { public static void main(String[] args) ...
- Day5 CSS基本样式和C3选择器
Day5 CSS基本样式和C3选择器 一.背景属性 1.背景颜色 background-color:transparent(默认值,透明); 颜色的取值: ...
- 从零开始的全栈工程师——js篇2.7(JS数据类型具体分析)
JS数据类型具体分析与数据的三大存储格式 1. 字符串 string2. 数字 number3. 布尔 boolean4. null 空5. undefined 未定义↑↑↑叫基本数据类型 基本数据类 ...
- BZOJ2216: [Poi2011]Lightning Conductor(DP 决策单调性)
题意 题目链接 Sol 很nice的决策单调性题目 首先把给出的式子移项,我们要求的$P_i = max(a_j + \sqrt{|i - j|}) - a_i$. 按套路把绝对值拆掉,$p_i = ...
- 巧用前端神器,fakerjs生成json文件
安装 cnpm install faker json-serve --save-dev 在目录下创建一个模板文件 示例 makeJson.js var faker = require('faker') ...
- HTML5&CSS挑战
地址:https://www.w3cschool.cn/codecamp/list?pename=html5_and_css_camp 开始学习HTML标签:欢迎来到编程训练营的第一个编程挑战!你可以 ...
- webpack 安装后提示CLI
webpack 4X 后需要安装webpack-cli 请注意需要安装在同一目录 npm install --save-dev webpack -g 输入以上命令后: webpack -v 提示: T ...
- 一个容易被忽视的css选择器
之前学的的迷糊了,也不知道什么会什么不会了,跑去面试了.别人列出一堆css选择器,本以为选择器没啥的,结果到那个多类选择器翻车了,.a.b选择同时含a,b类名的,很尴尬所以回来仔细整理了一下.目前根据 ...
- GCC 编译错误 relocation truncated to fit: R_X86_64_32S against `.bss'
问题如下图所示:(.text+0x53a): relocation truncated to fit: R_X86_64_32S against `.bss' 以前在Linux中编译程序,从来没有遇到 ...
- python数据类型、输入输出、运算符、条件判断、循环
变量以及类型 变量:存储程序运行中的数据,变量有3个要素:变量名.变量类型.变量值.python属于弱类型语言,不需要声明变量类型. [root@localhost python]# ipython3 ...