HUST 1377 - Sequence

1377 - Sequence

Time Limit: 1s Memory Limit:128MB

Submissions: 430 Solved: 144
Description

Given a number sequence whose length is n, you can delete at most k numbers in the sequence.
After that you are asked to answer the maximum length of longest continuous subsequence that
each number in it is larger than its previous number(if has any)by one.

Input

There are multy testcases. For each case:
the first line are the integer n, k. 1 <= n <= 100, 0 <= k <= n.
the seconde line is n numbers.

Output

For each case output one number representing the maximum length of the subsequence.

Sample Input
6 3
2 4 6 5 2 1
4 4
6 3 5 2
Sample Output
2
1
仔细看题会发现题目不难,注意题目中描述(红字),剩下就可以直接深搜,注意维护好每个数就好了。
AC代码:
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <string.h>
using namespace std;
int n,k,num[105],ans;
void dfs(int i,int del,int len)
{
    int j;
    if(del>k)
    {
        return;
    }
    for(j=i+1;j<=n;j++)
    {
        if(num[j]==num[i]+1)
        {
            dfs(j,del+j-i-1,len+1);
        }
    }
    if(del<=k&&len>ans)
    {
        ans=len;
    }
}
int main()
{
    int i;
    while(~scanf("%d%d",&n,&k))
    {
        for(i=1;i<=n;i++)
        {
            scanf("%d",&num[i]);
        }
        ans=-1;
        for(i=1;i<=n;i++)
        {
            dfs(i,0,1);
        }
        printf("%d\n",ans);
    }
    return 0;
}
















































SQL Prompt是Red Gate Software公司开发的一款强大的SQL代码编辑和优化工具,主要面向数据库开发者和管理员。版本11.0.1.16766是一个更新版本,它提供了更高效、更便捷的SQL编写环境,旨在提升SQL代码的可读性、效率和一致性。这个安装包包含了所有必要的组件,用于在用户的计算机上安装SQL Prompt工具。 SQL Prompt的核心功能包括自动完成、智能提示、格式化和重构。自动完成功能能够帮助用户快速输入SQL语句,减少键入错误;智能提示则基于上下文提供可能的选项,加快编写速度;格式化功能允许用户按照自定义或预设的编码规范对SQL代码进行美化,提升代码的可读性;而重构工具则可以帮助用户优化代码结构,消除潜在问题。 在描述中提到的“代码格式化规则来源于网络”,指的是用户可以通过下载网络上的json文件来扩展或定制SQL Prompt的代码格式化规则。这些json文件包含了特定的格式设置,如缩进风格、空格使用、注释位置等。将这些文件复制到指定的目录(例如:C:\Users\用户名\AppData\Local\Red Gate\SQL Prompt 10\Styles)后,SQL Prompt会读取这些规则并应用到代码格式化过程中,使得用户可以根据个人偏好或团队规范调整代码样式。 以下几点请注意: 1. 经实测,此版本支持最新的Sql Server 2022版的SSMS21 2. 此安装包中不包括keygen,请自行解决
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值