首页 > 其他 > 详细

hust 1377 - Sequence

时间:2014-05-19 22:18:02      阅读:398      评论:0      收藏:0      [点我收藏+]

题目描述

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
bubuko.com,布布扣
#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;
}
bubuko.com,布布扣

 

hust 1377 - Sequence,布布扣,bubuko.com

hust 1377 - Sequence

原文:http://www.cnblogs.com/chensunrise/p/3731365.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!