HDU 3998 SequenceL(多次LIS)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3998


Sequence

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2186    Accepted Submission(s): 789


Problem Description
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).
 

Input
The input file have many cases. Each case will give a integer number n.The next line will 
have n numbers.
 

Output
The 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
 

Source
 

Recommend
lcy   |   We have carefully selected several similar problems for you:   3996  1532  3549  3572  3416 
 


题目大意:求最长子序列和最长子序列的个数

解析:多次运用LIS算法,标记下即可

代码如下:

#include<iostream>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<string>
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#define N 22222
using namespace std;
const int inf = 0x3f3f3f3f;
const int mod = 998244353;
const double eps = 1e-8;
const double pi = acos(-1.0);
typedef long long LL;

int dp[N], a[N], book[N];

int main()
{
    int n, i;
    while(~scanf("%d", &n))
    {
        if(n == 0){ printf("0\n0\n"); continue;}
        for(i = 1; i <= n; i++)
            scanf("%d", &a[i]);
        int ans = 0, num;
        memset(book, 0, sizeof(book));
        while(1)
        {
            memset(dp, 0x3f, sizeof(dp));
            int k, kk; k = kk = 0;
            for(i = 1; i <= n; i++)
            {
                if(!book[i])
                {
                    *lower_bound(dp, dp + n, a[i]) = a[i];
                    k = lower_bound(dp, dp + n, inf) - dp;
                    if(k > kk) kk++, book[i] = 1;
                }

            }
            int r = lower_bound(dp, dp + n, inf) - dp;
            if(r > ans)
            {
                num = 1; ans = r;
            }
            else if(r == ans) num++;
            else break;
        }
        printf("%d\n", ans);
        printf("%d\n", num);
    }
    return 0;
}




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值