正反跑一次LIS,取最大的长度,如果长度大于n-k就满足条件。

ac代码:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <map>
#include <stack>
#include <algorithm>
using namespace std;
int
dp[];
int
LIS(int a[],int len)
{

int
ret=;
memset(dp,,sizeof(dp));
for
(int i=;i<=len;i++)
{

if
(a[i] > dp[ret]) dp[++ret]=a[i];
else

{

int
pos=lower_bound(dp+,dp+ret,a[i])-dp;
dp[pos]=a[i];
}
}

return
ret;
}

int
b[],c[];
int
main()
{

int
t;
scanf("%d",&t);
while
(t--)
{

int
n,k;
scanf("%d %d",&n,&k);
int
pos=n-;
for
(int i=;i<=n;i++)
{

scanf("%d",&b[i]);
c[pos--]=b[i];
}

int
mx=max(LIS(c,n),LIS(b,n));
if
(n-mx<=k) cout<<"A is a magic array."<<endl;
else
cout<<"A is not a magic array."<<endl;
}

return
;
}

心情不太好,过来这么久才整理代码。 感情这个东西,比算法难多了

hdu 6197 array array array LIS的更多相关文章

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

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

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

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

  3. 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 ...

  4. Array.fill & array padding

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

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

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

  6. HDU - 6197:array array array (简单LIS)

    One day, Kaitou Kiddo had stolen a priceless diamond ring. But detective Conan blocked Kiddo's path ...

  7. hdu 6197 array array array

    array array array Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  8. HDU - 6197 array array array (最长上升子序列&最长下降子序列)

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

  9. hdu 5280 Senior's Array

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5280 Senior's Array Description One day, Xuejiejie ge ...

随机推荐

  1. 常用的xml头文件

    原文:https://www.cnblogs.com/uniquezhangqi/p/9199329.html#commentform xmlns,xmlns:xsi,xsi:schemaLocati ...

  2. 设备树中的interrupts属性解析

    interrupts属性会有两种不同的参数: 1. 带两个参数的情形 示例:  interrupt-parent = <&gpio2>; interrupts = <5 1& ...

  3. 机器学习 - 算法 - 聚类算法 K-MEANS / DBSCAN算法

    聚类算法 概述 无监督问题 手中无标签 聚类 将相似的东西分到一组 难点 如何 评估, 如何 调参 基本概念 要得到的簇的个数  - 需要指定 K 值 质心 - 均值, 即向量各维度取平均 距离的度量 ...

  4. linux ubuntu 如何解决warning: no newline at end of file?

    今天写了一段代码, 是在Windows下编辑的, 保存后放在linux系统下编译. gcc和cc都产生以下的警告: a.h:1:2: warning: no newline at end of fil ...

  5. QDateTime QString

    QDateTime格式化  yyyy-MM-dd hh:mm:ss QString getFormatDateStr(QDateTime dateTimeParam) { qDebug() <& ...

  6. React——嵌入已有项目 && jsx

    Add React to a Website React has been designed from the start for gradual adoption, and you can use ...

  7. 阶段5 3.微服务项目【学成在线】_day17 用户认证 Zuul_15-网关-路由配置

    4.4 路由配置 4.4.1需求分析 Zuul网关具有代理的功能,根据请求的url转发到微服务,如下图: 客户端请求网关/api/learning,通过路由转发到/learning 客户端请求网关/a ...

  8. python根据数组数据绘图

    转载自网络,版权归原作者所有 hello3.txt文件内部数据如下 ......7,2,6,-12,-10,-7,-1,2,9,...... python脚本 import numpy as np i ...

  9. (1) Java实现JDBC连接及事务的方式

    许多数据库的auto-commit默认是ON的,比如MySQL,PostgresSQL等.当然也有默认是OFF的,比如Oracle(Oracle里面执行DML语句是需要手动commit的). 这里我们 ...

  10. React中如何实现模态框每次打开都是初始界面

    问题描述如下 解决方案:每次点击打开模态框的时候为,当前模态框设置一个独立的key值,代码如下: /* * 上传文件的模块框控制 * */ showFileModal = () => { thi ...