zoukankan      html  css  js  c++  java
  • hust 1377

    题目描述

    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.

    输入

    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.

    输出

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

    样例输入

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

    样例输出

    2
    1
    这个题目明显的水题,看题目一定要注意了,必须是只大于1,我标记了一下,然后就是水水的dfs
    #include<iostream>
    #include<cstdio>
    #include<cstring>
    using namespace std;
     
    int n,k,Len,a[101];
    void dfs(int i,int del,int len)
    {
        if (del>k) return;
        for (int j=i+1;j<=n;j++)
        {
            if (a[j]-1==a[i])
            dfs(j,del+j-i-1,len+1);
        }
        if (del<=k && len>Len) Len=len;
    }
     
    int main()
    {
        while (scanf("%d%d",&n,&k)!=EOF)
        {
            for (int i=1;i<=n;i++) scanf("%d",&a[i]);
            Len=-1;
            for(int i=1;i<=n;i++) dfs(i,0,1);
            printf("%d
    ",Len);
        }
        return 0;
    }
    至少做到我努力了
  • 相关阅读:
    远程连接telnet和ssh的区别?(telnet如何连接)
    NFS实践(搭建页面)
    NFS挂载 卸载
    NFS实践
    03 Linux 文件管理
    02 bashshell介绍使用
    01 Linux 的渊源与发展史
    P4218 [CTSC2010]珠宝商
    P5284 [十二省联考2019]字符串问题
    广义后缀自动机(广义SAM)
  • 原文地址:https://www.cnblogs.com/chensunrise/p/3731365.html
Copyright © 2011-2022 走看看