首页 > 代码库 > hust 1377 - Sequence

hust 1377 - Sequence

题目描述

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\n",Len);
    }
    return 0;
}