zoukankan      html  css  js  c++  java
  • SDUT_1299 最长上升子序列

    最长上升子序列

    Time Limit: 3000MS Memory Limit: 65536KB

    Problem Description

    一个数的序列bi,当b1 < b2 < ... < bS的时候,我们称这个序列是上升的。对于给定的一个序列(a1, a2, ..., aN),我们可以得到一些上升的子序列(ai1, ai2, ..., aiK),这里1<= i1 < i2 < ... < iK <= N。比如,对于序列(1, 7, 3, 5, 9, 4, 8),有它的一些上升子序列,如(1, 7), (3, 4, 8)等等。这些子序列中最长的长度是4,比如子序列(1, 3, 5, 8)。

    你的任务,就是对于给定的序列,求出最长上升子序列的长度。

    Input

    输入的第一行是序列的长度N (1 <= N <= 1000)。第二行给出序列中的N个整数,这些整数的取值范围都在0到10000。

    Output

    最长上升子序列的长度。

    Example Input

    7
    1 7 3 5 9 4 8
    Example Output
    4
    
    #include <iostream>
    #include <algorithm>
    using namespace std;
    int main()
    {
        int array[1010],Max[1010];
        int n;
        cin>>n;
        for(int i=0;i<n;++i)
           {
               cin>>array[i];
               Max[i]=1;
           }
        for(int i=1;i<n;++i)
            for(int j=0;j<i;++j)
            if(array[i]>array[j])
            Max[i]=max(Max[i],Max[j]+1);
            cout<<*max_element(Max,Max+n);
            return 0;
    }
    

  • 相关阅读:
    【monkey测试】Fragment not attached to Activity
    android加载字体内存泄漏的处理方法
    性能测试—瓶颈分析方法
    EXT 环境部署
    测试用例设计
    软件测试职业规划
    mysql存储过程
    testlink安装
    并崩溃原因及解决方案
    MySQL正则表达式
  • 原文地址:https://www.cnblogs.com/sxy201658506207/p/7586286.html
Copyright © 2011-2022 走看看