正反跑一次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
;
}

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

最新文章

  1. java.lang.reflect.Field
  2. Libevent 定时器
  3. BestCoder Round #86 部分题解
  4. BZOJ1634: [Usaco2007 Jan]Protecting the Flowers 护花
  5. Java 多线程 笔记 转自http://www.cnblogs.com/lwbqqyumidi/p/3804883.html
  6. 微信小程序开发之微信支付
  7. Java多线程之赛跑游戏
  8. $(this) 和 this 关键字在 jquery 中有何不同?
  9. Go Example--工作池
  10. 关于zynq7 中MIO的理解
  11. [转载]java开发中的23种设计模式
  12. OWASP TOP10(2017)
  13. Python glob.md
  14. (纪录片)《星际穿越》中的科学 The Science of Interstellar
  15. 基于jQuery CSS3鼠标点击动画效果
  16. 闲:测试memcpy和std::copy vector之间拷贝
  17. H.264:FFMpeg 实现简单的播放器
  18. Java 设计模式系列(二三)访问者模式(Vistor)
  19. Shiro框架简介
  20. LeetCode Best Time to Buy and Sell Stock with Transaction Fee

热门文章

  1. linux下 安装 ImageMagick 及其 php imagick扩展(转)
  2. Qt代码配色VS2015风格
  3. C# 使用Task执行异步操作
  4. Ionic 的安装运行
  5. SpringMVC源码分析--HandlerMappings
  6. 使用MockMvc进行springboot调试(SpringbootTest)
  7. HTTP连接详解
  8. redis未设置idle超时时间导致连接过多
  9. Tools - Tcpdump
  10. jenkins:从FTP服务器下载文件