zoukankan      html  css  js  c++  java
  • POJ2533——Longest Ordered Subsequence(简单的DP)

    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

    题目大意:

        给定一个数列,输出其最长递增子序列的长度。

    解题思路:

        水题,不解释。

    Code:

     1 /*************************************************************************
     2     > File Name: poj2533.cpp
     3     > Author: Enumz
     4     > Mail: 369372123@qq.com
     5     > Created Time: 2014年10月27日 星期一 20时07分22秒
     6  ************************************************************************/
     7 
     8 #include<iostream>
     9 #include<cstdio>
    10 #include<cstdlib>
    11 #include<string>
    12 #include<cstring>
    13 #include<list>
    14 #include<queue>
    15 #include<stack>
    16 #include<map>
    17 #include<set>
    18 #include<algorithm>
    19 #include<cmath>
    20 #include<bitset>
    21 #include<climits>
    22 #define MAXN 1001
    23 using namespace std;
    24 int date[MAXN];
    25 int dp[MAXN];
    26 int main()
    27 {
    28     int N;
    29     while (cin>>N)
    30     {
    31         for (int i=1;i<=N;i++)
    32             cin>>date[i];
    33         for (int i=1;i<=MAXN-1;i++)
    34             dp[i]=1;
    35         int Max=1;
    36         for (int i=2;i<=N;i++)
    37         {
    38             for (int j=1;j<=i-1;j++)
    39                 if (date[j]<date[i])
    40                     dp[i]=max(dp[i],dp[j]+1);
    41             Max=max(Max,dp[i]);
    42         }
    43         cout<<Max<<endl;
    44     }
    45     return 0;
    46 }
  • 相关阅读:
    js组件常用封装方法。。。。。【组件封装】 ★★★★★★ 1月会员日 集人气【弹窗】
    以后开公司用的资源瞎记录
    SpringSecurityFilter 链
    分布式系统数据一致性的6种方案(转)
    统一日志监控系统 springboot websocket 作品
    MyBatis generator 使用方式 小结
    swagger and restful api 参考
    kafka linux 启动脚本 sample
    转 CAS实现SSO单点登录原理
    江南白衣 Java性能优化PPT
  • 原文地址:https://www.cnblogs.com/Enumz/p/4062934.html
Copyright © 2011-2022 走看看