cf 1029 B.Creating the Contest(dp)

【题目】

B. Creating the Contest

【题解】

题意:给定一个递增的序列,构造一个后一项不大于前一项的两倍的最长子序列(可不连续),输出长度。

思路:虽然题意说是构造的子序列可不连续,但是因为原始序列具有单调性,所以肯定是连续的,所以我们只需要比较每一段符合要求的子序列的长度即可。

【代码】

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#define mem(a) memset(a,0,sizeof(a))
#define go(i,a,b) for(int i=a;i<=b;i++)
#define og(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int maxn=1e5+5;
const int inf=0x3f3f3f3f;
typedef long long ll;
typedef unsigned long long ull;
main()
{
    int n,a[2*maxn],dp[2*maxn];
    scanf("%d",&n);
    go(i,1,n) scanf("%d",&a[i]);
    int l=1,ans=1;dp[1]=a[1];
    go(i,2,n)
    {
        if(a[i]<=dp[l]*2) dp[++l]=a[i];
        else
        {
            ans=max(ans,l);
            l=1;
            dp[l]=a[i];
        }
    }
    ans=max(ans,l);
    printf("%d\n",ans);
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值