1037: I want you!(最长上升子序列)

【题目】

1037: I want you!

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 298  Solved: 76
[Submit][Status][Web Board]

Description

Given an array Ai(0<=i<n), its length is n; We want to find an another array Bi , which is 0 or 1,and its length is n too;

Besides, Ai and Bi meets the following conditions:

If neither A[i]*B[i] nor A[j]*B[j] equals to 0, then A[i]*B[i] < A[j]*B[j];(0<=i<j<n)

Now , we want to know the maximum of ∑Bi(0<=i<n) you can get.

Input

The input consists of multiple test cases。For each test case ,the first line contains one integer n (1<n<=300).Next line contains n integers.

Output

For each case, output the maximum of ∑Bi.

Sample Input

6
1 2 3 4 5 6
4
3 2 3 6

Sample Output

6
3

【题解】

题意:输出给定序列的最长上升子序列的长度加上所包含的0的个数.

【代码】

#include<bits/stdc++.h>
using namespace std;
main()
{
    int n,a[305],b[305];
    while(~scanf("%d",&n))
    {
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);
        int l=1,sum=0;b[1]=a[0];
        for(int i=1;i<n;i++)
            if(a[i]==0)
               sum++;
            else if(a[i]>b[l])
               b[++l]=a[i];
            else
            {
                int t=upper_bound(b+1,b+l+1,a[i])-b;
                b[t]=a[i];
            }
        printf("%d\n",l+sum);
    }
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值