Time limit2000 ms

Memory limit65536 kB

A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequence of the given numeric sequence ( a1a2, ..., aN) be any sequence ( ai1ai2, ..., 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

题意 求最大上升子序列的长度题解 dp[i]就是以a[i]为末尾的最长上升子序列的长度,我写的是O(n^2)的复杂度,也可以用二分查找去找,那个是O(nlog n)
#include<iostream>
#include<algorithm>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<stack>
using namespace std;
#define PI 3.14159265358979323846264338327950
#define INF 0x3f3f3f3f;

int n;
];
];
void solve()
{
    ;
    ;i<n;i++)
    {
        dp[i]=;
        ;j<i;j++)
        {
            if(a[j]<a[i])
            {
                dp[i]=max(dp[i],dp[j]+);
            }

        }
        res=max(res,dp[i]);

    }
    printf("%d\n",res);
}
int main()
{
    cin>>n;
    ;i<n;i++)
        cin>>a[i];
    solve();
}

poj-2533 longest ordered subsequence(动态规划)的更多相关文章

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

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

  2. POJ 2533 Longest Ordered Subsequence(裸LIS)

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

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

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

  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(最长上升子序列(NlogN)

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

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

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

  7. poj 2533 Longest Ordered Subsequence(LIS)

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

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

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

  9. Poj 2533 Longest Ordered Subsequence(LIS)

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

  10. POJ - 2533 Longest Ordered Subsequence与HDU - 1257 最少拦截系统 DP+贪心(最长上升子序列及最少序列个数)(LIS)

    Longest Ordered Subsequence A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let ...

随机推荐

  1. 中间件注册可以除了可以使用Startup之外,还可以选择StartupFilter

    中间件注册可以除了可以使用Startup之外,还可以选择StartupFilter 中间件的注册除了可以借助Startup对象(DelegateStartup或者ConventionBasedStar ...

  2. Win10 插入耳机后没有声音,拔出后电脑有声音

  3. MVC 知识点总结

    [此篇文章收录于其他博客,作为笔记使用] 一·  MVC MVC设计模式->MVC框架(前端开发框架),asp.net(webform) aspx M:Model (模型,负责业务逻辑处理,比如 ...

  4. 最全的Spring注解详解

    @Configuration : 配置类 == 配置文件,告诉Spring这是一个配置类@ComponentScan(value="com.atguigu",excludeFilt ...

  5. IO流----转换流、缓冲流

    打开一个文本文件,另存为: Ansi就是系统默认编码(就是gbk) 建一个编码是utf-8的txt文件, 例: import java.io.FileWriter; import java.io.IO ...

  6. 【Unity3D】3D游戏学习

    1.理解游戏元素,简单回答以下问题: 1.1简单介绍一款上世纪(19XX)出品的计算机游戏,然后按课件的方法描述游戏的五个基本元素.(讲目标.玩法.规则) 1.1.1仙剑奇侠传 <仙剑奇侠传&g ...

  7. jQuery toggle 使用

    jQuery 中 toggle 作用 切换元素的显示与隐藏状态 如果被选元素可见,则隐藏这些元素,如果被选元素隐藏,则显示这些元素. <body> <div class=" ...

  8. Chrome Java插件过期

    企业应用软件中,基本都是基于某个版本的JDK进行开发的,更新跟不上Oracle更新的步伐,Chrome浏览器自动默认关闭了过期插件导致用Chrome无法打开应用软件. 解决办法如下:

  9. SqlServer中嵌套事务使用--事务计数指示 BEGIN 和 COMMIT 语句的数目不匹配 --根本问题

    转自  :SqlServer中嵌套事务使用--事务计数指示 BEGIN 和 COMMIT 语句的数目不匹配 --根本问题 问题: 1. System.Data.SqlClient.SqlExcepti ...

  10. 突然心血来潮,想写写我在java面试中遇到的事。作为一个应届生,我觉得我的情况都与大部分应届生是差不多的,希望你们能在这上面得到一些有用的

    面试过程吧,怎么说呢?从一开始接触面试到现在成功了几家,这中间我确实收获了许多,那我就从我第一次面试开始讲吧. 第一次面试是有人介绍过来的,总之还是有一位贵人相助,所以第一次面试时,面试官很好没有怎么 ...