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的更多相关文章

  1. POJ 2533-Longest Ordered Subsequence(DP)

    Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 34454   Acc ...

  2. POJ 2533 Longest Ordered Subsequence(LIS模版题)

    Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 47465   Acc ...

  3. poj 2533 Longest Ordered Subsequence 最长递增子序列

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4098562.html 题目链接:poj 2533 Longest Ordered Subse ...

  4. POJ 2533 - Longest Ordered Subsequence - [最长递增子序列长度][LIS问题]

    题目链接:http://poj.org/problem?id=2533 Time Limit: 2000MS Memory Limit: 65536K Description A numeric se ...

  5. POJ 2533 Longest Ordered Subsequence(裸LIS)

    传送门: http://poj.org/problem?id=2533 Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 6 ...

  6. POJ 2533 Longest Ordered Subsequence(最长上升子序列(NlogN)

    传送门 Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subseque ...

  7. POJ 2533 Longest Ordered Subsequence 最长递增序列

      Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequenc ...

  8. poj 2533 Longest Ordered Subsequence(LIS)

    Description A numeric sequence of ai is ordered ifa1 <a2 < ... < aN. Let the subsequence of ...

  9. POJ 2533 Longest Ordered Subsequence(DP 最长上升子序列)

    Longest Ordered Subsequence Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 38980   Acc ...

随机推荐

  1. idea关闭sonar自动扫描

    file-setting-other setting-sonar相关的setting全部关闭

  2. servlet和jsp存值和取值的方式

    在servlet和jsp中存值和取值的方式由两种 1种是setAttribute和getAttribute 2种是c:forEach

  3. [转]Git之忽略文件(ignore file)

    原文链接:http://blog.csdn.net/benkaoya/article/details/7932370 .gitignore 配置文件用于配置不需要加入版本管理的文件,配置好该文件可以为 ...

  4. Retrofit 2.0:有史以来最大的改进

    因为其简单与出色的性能,Retrofit 是安卓上最流行的HTTP Client库之一. 不过它的缺点是在Retrofit 1.x中没有直接取消正在进行中任务的方法.如果你想做这件事必须手动杀死,而这 ...

  5. SQL优化 · 经典案例 · 索引篇

    Introduction 在这些年的工作之中,由于SQL问题导致的数据库故障层出不穷,下面将过去六年工作中遇到的SQL问题总结归类,还原问题原貌,给出分析问题思路和解决问题的方法,帮助用户在使用数据库 ...

  6. 在SAP云平台的CloudFoundry环境下消费ABAP On-Premise OData服务

    我的前一篇文章 使用Java+SAP云平台+SAP Cloud Connector调用ABAP On-Premise系统里的函数介绍了在SAP云平台的Neo环境下如何通过SAP Cloud Conne ...

  7. java 的http请求方式:HttpURLConnection和HttpClient

    1.要了解一些概念性的东西,比如Http的协议以及协议头等一些东东 2.HttpURLConnection一般步骤:创建URL对象==>获取URL的HttpURLConnection对象实例== ...

  8. UVA 11404 Plalidromic Subsquence (回文子序列,LCS)

    最长回文子序列可以用求解原串s和反转串rv的LCS来得到,因为要求回文串分奇偶,dp[i][j]保存长度, 要求字典序最小,dp[i][j]应该表示回文子序列的端点,所以边界为单个字符,即i+j=le ...

  9. 【洛谷5390】[Cnoi2019] 数学作业(位运算)

    点此看题面 大致题意: 给你一个集合,求所有子集异或和之和. 大致思路 首先,我们很容易想到去对二进制下每一位分别讨论. 枚举当前位,并设共有\(x\)个数当前位上为\(1\),则有\((n-x)\) ...

  10. 【BZOJ1562】[NOI2009] 变换序列(匈牙利算法)

    点此看题面 大致题意: 给你一个长度为\(n\)的序列\(D\),让你找到一个字典序最小的\(n\)的排列\(T\),满足\(D_i=min(|T_i-i|,n-|T_i-i|)\). 建图 我想建图 ...