zoukankan      html  css  js  c++  java
  • hdu 3998 Sequence

    There is a sequence X (i.e. x[1], x[2], ..., x[n]). We define increasing subsequence of X
    as x[i1], x[i2],...,x[ik], which satisfies follow conditions:
    1) x[i1] < x[i2],...,<x[ik];
    2) 1<=i1 < i2,...,<ik<=n

    As an excellent program designer, you must know how to find the maximum length of the
    increasing sequense, which is defined as s. Now, the next question is how many increasing
    subsequence with s-length can you find out from the sequence X.

    For example, in one case, if s = 3, and you can find out 2 such subsequence A and B from X.
    1) A = a1, a2, a3. B = b1, b2, b3.
    2) Each ai or bj(i,j = 1,2,3) can only be chose once at most.

    Now, the question is:
    1) Find the maximum length of increasing subsequence of X(i.e. s).
    2) Find the number of increasing subsequence with s-length under conditions described (i.e. num).

    InputThe input file have many cases. Each case will give a integer number n.The next line will
    have n numbers.OutputThe output have two line. The first line is s and second line is num.Sample Input
    4
    3 6 2 5
    Sample Output
    2
    2

    最长上升子序列。
    代码:
    #include <iostream>
    #include <cstdio>
    #include <algorithm>
    #include <cstring>
    #include <map>
    #define Max 1000
    using namespace std;
    int n,s[Max],vis[Max];///vis标记是否已经使用
    int maxl()
    {
        int res = 0,t[Max];
        for(int i = 0;i < n;i ++)
        {
            if(vis[i])continue;
            if(!res || t[res - 1] < s[i])
            {
                t[res ++] = s[i];
                vis[i] = 1;
            }
            else
            {
    //            *lower_bound(t,t + res,s[i]) = s[i];
                int l = 0,r = res,mid;
                while(l < r)
                {
                    mid = (l + r) / 2;
                    if(t[mid] >= s[i])r = mid;
                    else l = mid + 1;
                }
                t[l] = s[i];
            }
        }
        return res;
    }
    int main()
    {
        while(scanf("%d",&n) != EOF)
        {
            for(int i = 0;i < n;i ++)
            {
                scanf("%d",&s[i]);
            }
            memset(vis,0,sizeof(vis));
            int m = maxl(),c = 1;
            while(maxl() == m)c ++;
            printf("%d
    %d
    ",m,c);
        }
    }
  • 相关阅读:
    C# 进程间通信之二传递复杂数据类型(转)
    c# 进程间的通信实现之一简单字符串收发
    WinRAR压缩操作帮助类
    软件推荐:扫码格式检测系统
    C#位操作(转)
    浅析c#内存泄漏
    常用SQL语句
    linux下网站搭建
    VS中的活动debug和活动cpu
    让程序员跳槽的非钱原因
  • 原文地址:https://www.cnblogs.com/8023spz/p/9008803.html
Copyright © 2011-2022 走看看