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 }
  • 相关阅读:
    大伯的八十岁寿辰
    收到 wincore.cpp 中一个 " ASSERT " BUG: 当 MFC 应用程序 Visual C++ 中 MFC 规则 DLL 中调用函数声明
    命名空间Microsoft.Office.Interop.Word不存在....
    中国测绘科学研究院招聘WEBGIS开发工程师与客座研究生
    开源GIS学习笔记 sinoly BLOGJAVA
    2007年7月9日星期一
    转载:使用感受: VC2005 VC6.0
    推荐:用ogr和PIL把矢量数据转化成栅格图像
    《赢在中国》感言
    VS2005的断点无效问题
  • 原文地址:https://www.cnblogs.com/Enumz/p/4062934.html
Copyright © 2011-2022 走看看