题意:对于一个序列,要求去掉正好K个数字,若能使其成为不上升子序列或不下降子序列,则“A is a magic array.”,否则"A is not a magic array.\n"。

分析:

1、求一遍LCS,然后在将序列逆转,求一遍LCS,分别可得最长上升子序列和最长下降子序列的长度tmp1、tmp2。

2、n - tmp1 <= k或n - tmp2 <= k即可,需要去掉的去完之后,在已经是最长上升或最长下降的序列中随便去够k个就好了。

  1. #include<cstdio>
  2. #include<cstring>
  3. #include<cstdlib>
  4. #include<cctype>
  5. #include<cmath>
  6. #include<iostream>
  7. #include<sstream>
  8. #include<iterator>
  9. #include<algorithm>
  10. #include<string>
  11. #include<vector>
  12. #include<set>
  13. #include<map>
  14. #include<stack>
  15. #include<deque>
  16. #include<queue>
  17. #include<list>
  18. #define lowbit(x) (x & (-x))
  19. const double eps = 1e-8;
  20. inline int dcmp(double a, double b){
  21. if(fabs(a - b) < eps) return 0;
  22. return a > b ? 1 : -1;
  23. }
  24. typedef long long LL;
  25. typedef unsigned long long ULL;
  26. const int INT_INF = 0x3f3f3f3f;
  27. const int INT_M_INF = 0x7f7f7f7f;
  28. const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
  29. const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
  30. const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
  31. const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
  32. const int MOD = 1e9 + 7;
  33. const double pi = acos(-1.0);
  34. const int MAXN = 100000 + 10;
  35. const int MAXT = 10000 + 10;
  36. using namespace std;
  37. int a[MAXN], dp[MAXN];
  38. int main(){
  39. int T;
  40. scanf("%d", &T);
  41. while(T--){
  42. int n, k;
  43. scanf("%d%d", &n, &k);
  44. for(int i = 0; i < n; ++i){
  45. scanf("%d", &a[i]);
  46. }
  47. memset(dp, INT_INF, sizeof dp);
  48. for(int i = 0; i < n; ++i){
  49. *lower_bound(dp, dp + n, a[i]) = a[i];
  50. }
  51. int tmp1 = lower_bound(dp, dp + n, INT_INF) - dp;
  52. if(n - tmp1 <= k){
  53. printf("A is a magic array.\n");
  54. }
  55. else{
  56. reverse(a, a + n);
  57. memset(dp, INT_INF, sizeof dp);
  58. for(int i = 0; i < n; ++i){
  59. *lower_bound(dp, dp + n, a[i]) = a[i];
  60. }
  61. int tmp2 = lower_bound(dp, dp + n, INT_INF) - dp;
  62. if(n - tmp2 <= k){
  63. printf("A is a magic array.\n");
  64. }
  65. else{
  66. printf("A is not a magic array.\n");
  67. }
  68. }
  69. }
  70. return 0;
  71. }

  

HDU - 6197 array array array (最长上升子序列&最长下降子序列)的更多相关文章

  1. hdu 6197 2017 ACM/ICPC Asia Regional Shenyang Online array array array【最长不上升子序列和最长不下降子序列】

    hdu 6197 题意:给定一个数组,问删掉k个字符后数组是否能不减或者不增,满足要求则是magic array,否则不是. 题解:队友想的思路,感觉非常棒!既然删掉k个后不增或者不减,那么就先求数组 ...

  2. HDU 6197 array array array 2017沈阳网络赛 LIS

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6197 题意:给你n个数,问让你从中删掉k个数后(k<=n),是否能使剩下的序列为非递减或者非递增 ...

  3. LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++>

    LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++> 给出排序好的一维数组,如果一个元素重复出现的次数 ...

  4. js Array.from & Array.of All In One

    js Array.from & Array.of All In One 数组生成器 Array.from The Array.from() static method creates a ne ...

  5. Array.fill & array padding

    Array.fill & array padding arr.fill(value[, start[, end]]) https://developer.mozilla.org/en-US/d ...

  6. hdu 4604 Deque(最长不下降子序列)

    从后向前对已搜点做两遍LIS(最长不下降子序列),分别求出已搜点的最长递增.递减子序列长度.这样一直搜到第一个点,就得到了整个序列的最长递增.递减子序列的长度,即最长递减子序列在前,最长递增子序列在后 ...

  7. HDU 6357.Hills And Valleys-字符串非严格递增子序列(LIS最长非下降子序列)+动态规划(区间翻转l,r找最长非递减子序列),好题哇 (2018 Multi-University Training Contest 5 1008)

    6357. Hills And Valleys 自己感觉这是个好题,应该是经典题目,所以半路选手补了这道字符串的动态规划题目. 题意就是给你一个串,翻转任意区间一次,求最长的非下降子序列. 一看题面写 ...

  8. HDU 1160 FatMouse's Speed (动态规划、最长下降子序列)

    FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. hdu 1160 FatMouse's Speed(最长不下降子序列+输出路径)

    题意: FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to ...

随机推荐

  1. css中class后面跟两个类,这两个类用空格隔开

    css中class后面跟两个类,这两个类用空格隔开,那么这两个类对这个元素都起作用,如果产生冲突,那么后面的类将替代前面的类.

  2. python随机函数.2020.2.26

    随机生成函数: import random  //首先要引用random模板 print(random.randint(0,9))     //random的语法 random.randint(0,9 ...

  3. 企业面试问题收集-ssm框架

    springMVC 1)    简单介绍下你对springMVC的理解? Spring MVC Framework有这样一些特点: 1.它是基于组件技术的.全部的应用对象,无论控制器和视图,还是业务对 ...

  4. #P1099 树网的核 题解

    题目描述 pdf 题解 这一题,刚开始看题目感觉好像很难,题目又长……一看数据范围,呵呵. 已经给出来这是个DAG,所以不用担心连通性的问题.那么怎么做呢? 朴素的做法是把树的直径的两个端点都统计出来 ...

  5. iOS沙盒目录简介、沙盒路径获取

    一.沙盒的意义 出于安全的考虑,iOS系统的沙盒机制规定每个应用只能访问当前沙盒目录下面的文件.但是对于一些用户级别的数据,考虑到很多软件都需要使用其中的数据,用户可以通过对当前的软件授权,让当前的应 ...

  6. HTML的几个注意点

    一.HTML 1.HTML5有哪些新特性?新增的标签有哪些? 新特性: 语义标签——语义化标签使得页面的内容结构化,见名知义 增强型表单——拥有多个新的表单 Input 输入类型.这些新特性提供了更好 ...

  7. HTML<head></head>中标签的含义

    我们都知道,HTML的标签可以分为很多种,head 里面的我们称为元信息类标签,诸如title.meta.style.link.base.script这些,他们用来描述文档的一些基本信息. 1. ti ...

  8. 神机iPhone6停产,苹果产业链应该感谢它还是痛恨它?

    据国内媒体报道,一些苹果上游供应商已经接到通知,iPhone6系列将会在5月底彻底停产,一时间,竟在网络上引发汹涌的怀念之情.iPhone6的特别之处在于它是苹果第一款大屏幕的智能手机,标志着库克彻底 ...

  9. 一、jsp和Servlet基础理论及jstl和EL表达式用法

    1.题外话:使用JSP有近一年半的时间了,但是开发量不大.昨天部门突然让做个读取EXCLE文件,然后在前台页面进行展示.并通过点击查看按钮可以对每条明细记录进行跳转后进行详情查看,并按照页面原型进行页 ...

  10. jQuery加减

    var num1 = 123; var num2=123; var sum = num1+num2; 结果是246; <input type="text" id=" ...