练习-codevs-1576最长严格上升子序列

1576 最长严格上升子序列

时间限制: 1 s
空间限制: 256000 KB
题目等级 : 黄金 Gold

题目描述 Description

给一个数组a1, a2 … an,找到最长的上升降子序列ab1< ab2 < … < abk,其中b1< b2<..bk。

输出长度即可。
输入描述 Input Description

第一行,一个整数N。

第二行 ,N个整数(N < = 5000)
输出描述 Output Description

输出K的极大值,即最长不下降子序列的长度
样例输入 Sample Input

5

9 3 6 2 7
样例输出 Sample Output

3
数据范围及提示 Data Size & Hint

【样例解释】

最长不下降子序列为3,6,7

#include <stdio.h>
#include <stdlib.h>

#define f(x) (*(data+x))

int *data;
int length;
int n;

void dp(int num,int last,int s)
{
    if(num==n)
    {
        if(s>length)
        {
            length=s;
        }
        return;
    }
    if(f(num)>last)
    {
        dp(num+1,f(num),s+1);
    }
    dp(num+1,last,s);
    return;
}
int main()
{
    int i;
    scanf("%d",&n);
    data=(int*)malloc(sizeof(int)*n);
    for(i=0;i<n;i++)
        scanf("%d",data+i);
    dp(0,0,0);
    printf("%d\n",length);
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值