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 }
  • 相关阅读:
    超链接把一个值传到多个页面的方法
    jsp采用数据库连接池的方法获取数据库时间戳context.xml配置,jsp页面把时间格式化成自己需要的格式
    Myeclipse WEB工程JSP使用JNDI 数据库连接池连接Mysql数据库
    jsp页面图片显示不出来
    如何修改MyEclipse的默认编码方式
    MyEclipse8.5破解方法
    mysql创建的数据库在电脑什么位置?
    netsh winsock reset
    SQL Server(MSSQLSERVER)启动失败,提示“请求失败或服务未及时响应
    WIN7不能上网
  • 原文地址:https://www.cnblogs.com/ohyee/p/5451491.html
Copyright © 2011-2022 走看看