zoukankan      html  css  js  c++  java
  • POJ 2533.Longest Ordered Subsequence

    Longest Ordered Subsequence
    Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u
    SubmitStatusPracticePOJ 2533

    Description

    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

    模板题,最长上升子序列

    套用模板即可

    AC代码:GitHub

     1 /*
     2 By:OhYee
     3 Github:OhYee
     4 HomePage:http://www.oyohyee.com
     5 Email:oyohyee@oyohyee.com
     6 Blog:http://www.cnblogs.com/ohyee/
     7 
     8 かしこいかわいい?
     9 エリーチカ!
    10 要写出来Хорошо的代码哦~
    11 */
    12 
    13 
    14 #include <cstdio>
    15 #include <algorithm>
    16 #include <cstring>
    17 #include <cmath>
    18 #include <string>
    19 #include <iostream>
    20 #include <vector>
    21 #include <list>
    22 #include <queue>
    23 #include <stack>
    24 #include <map>
    25 using namespace std;
    26 
    27 //DEBUG MODE
    28 #define debug 0
    29 
    30 //循环
    31 #define REP(n) for(int o=0;o<n;o++)
    32 
    33 const int maxn = 1005;
    34 int n;
    35 int a[maxn];
    36 
    37 class LIS_stack {
    38 private:
    39     static const int SIZE = maxn;
    40     int len;//长度
    41     int Stack[SIZE];
    42 public:
    43     LIS_stack() {
    44         len = 0;
    45         memset(Stack,0,sizeof(Stack));
    46     }
    47     void push(int num) {
    48         if(len == 0 || Stack[len - 1] < num) {
    49             Stack[len++] = num;
    50         } else {
    51             for(int i = 0;i < len;i++) {
    52                 if(Stack[i] > num) {
    53                     Stack[i] = num;
    54                     break;
    55                 }
    56             }
    57         }
    58     }
    59     int lenth() {
    60         return len;
    61     }
    62 
    63 };
    64 
    65 int LIS(int *a,int len) {
    66     LIS_stack s;
    67     for(int i = 0;i < len;i++) 
    68         s.push(a[i]);
    69     return s.lenth();
    70 }
    71 
    72 bool Do() {
    73     if(scanf("%d",&n) == EOF)
    74         return false;
    75     REP(n)
    76         scanf("%d",&a[o]);
    77 
    78     printf("%d
    ",LIS(a,n));
    79 
    80     return true;
    81 }
    82 
    83 int main() {
    84     while(Do());
    85     return 0;
    86 }
  • 相关阅读:
    Lucene 全文检索
    Redis 集群
    Redis 初步接触
    Mybatis
    FastJson 介绍
    JAVA微信企业付款到零钱(十分钟搞定),附完整DEMO下载
    持续集成与Devops关系
    GIT命令行统计代码提交行数
    一种简单的REST API接口加密实现,只允许自己的产品调用后台,防止接口被刷
    Beyond Compare 4.X 破解方法(亲测有效)
  • 原文地址:https://www.cnblogs.com/ohyee/p/5451491.html
Copyright © 2011-2022 走看看