首页 > 代码库 > 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; }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。