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. Android Bitmap(位图)详解

    一.背景 在Android开发中,任何一个APP都离不开图片的加载和显示问题.这里的图片来源分为三种:项目图片资源文件(一般为res/drawable目录下的图片文件).手机本地图片文件.网络图片资源 ...

  2. java join 方法的使用

    在很多情况下,主线程创建并启动子线程,如果子线程中要进行大量的耗时运算,主线程往往将早于子线程结束之前结束.这时,如果主线程想等待子线程执行完成之后再结束,比如子线程处理一个数据,主线程要取得这个数据 ...

  3. SQL判断一个事件段 是否在数据库中与其他时间段有重叠 判断时间重叠

    数据库字段startDate 开始时间   endDate 结束时间  -两个参数 比如查2-2  至2-6 在数据库中是否与其他时间有重叠 四个条件有一项满足则有重叠时间 思路是这样子 以开始和结束 ...

  4. NIO学习之Channel

    一.Channel基础 通道是一个对象,通过它可以读取和写入数据,Channel就是通向什么的道路,为数据的流向提供渠道: 在传统IO中,我们要读取一个文件中的内容使用Inputstream,该str ...

  5. I/O————流

    流的关系图 缓冲流分为字节和字符缓冲流(图中是经常用的搭配,PrintWrite与BufferedWrite都继承java.io.Write) 字节缓冲流为: BufferedInputStream— ...

  6. java的三大特性之一继承概述

    0.继承-----注意事项 00.子类最多只能继承一个父类(指直接继承) 01.java所有的类都是Object的子类 02.JPK6.0中有202个包3777个类,接口,异常,枚举,注释和错误 03 ...

  7. windows下安装pm2

    安装pm2 npm install pm2 -g 添加系统环境变量 PM2_HOME=C:\Users\PCONE\.pm2 打开新的cmd命令行窗口,执行以下命令来安装服务 pm2-service- ...

  8. Vue.js-this详解

    this this 指向并不是在函数定义的时候确定的,而是在调用的时候确定的.换句话说,函数的调用方式(直接调用.方法调用.new调用.bind.call.apply.箭头函数)决定了 this 指向 ...

  9. 在CesiumVR基础上实现3D左右立体视觉

    整体思路 在VR模块的基础上调整视差,使其随距离发生变化: 左右分屏时,需要将左右屏的横向进行1/2压缩:这是因为3D-TV在对左右格式影像进行合并时,会进行拉伸: 左屏幕的相机相对于原来的(右屏)相 ...

  10. Connectivity

    6492: Connectivity 时间限制: 1 Sec  内存限制: 128 MB提交: 118  解决: 28[提交][状态][讨论版][命题人:admin] 题目描述 There are N ...