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 }
  • 相关阅读:
    Linux 基础与应用教程 003(权限管理命令简单基础)
    Linux 基础与应用教程 002
    Android:监听音键并屏蔽系统的音量调节
    Android:用Seekbar来调节屏幕亮度
    Android:获得一个竖的seekbar
    python之路(4)高阶函数和python内置函数
    python之路(3)函数和匿名函数
    python之路(2)集合(set)和字符串格式化
    python之路(1)数据类型
    SD从零开始03-04
  • 原文地址:https://www.cnblogs.com/Enumz/p/4062934.html
Copyright © 2011-2022 走看看