hdu 6197 array array array LIS
正反跑一次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的更多相关文章
- hdu 6197 2017 ACM/ICPC Asia Regional Shenyang Online array array array【最长不上升子序列和最长不下降子序列】
hdu 6197 题意:给定一个数组,问删掉k个字符后数组是否能不减或者不增,满足要求则是magic array,否则不是. 题解:队友想的思路,感觉非常棒!既然删掉k个后不增或者不减,那么就先求数组 ...
- LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++>
LeetCode 80 Remove Duplicates from Sorted Array II [Array/auto] <c++> 给出排序好的一维数组,如果一个元素重复出现的次数 ...
- 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 ...
- Array.fill & array padding
Array.fill & array padding arr.fill(value[, start[, end]]) https://developer.mozilla.org/en-US/d ...
- HDU 6197 array array array 2017沈阳网络赛 LIS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6197 题意:给你n个数,问让你从中删掉k个数后(k<=n),是否能使剩下的序列为非递减或者非递增 ...
- HDU - 6197:array array array (简单LIS)
One day, Kaitou Kiddo had stolen a priceless diamond ring. But detective Conan blocked Kiddo's path ...
- hdu 6197 array array array
array array array Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDU - 6197 array array array (最长上升子序列&最长下降子序列)
题意:对于一个序列,要求去掉正好K个数字,若能使其成为不上升子序列或不下降子序列,则“A is a magic array.”,否则"A is not a magic array.\n&qu ...
- hdu 5280 Senior's Array
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5280 Senior's Array Description One day, Xuejiejie ge ...
随机推荐
- Go 与 JSON
Go 中通过标准库encoding/json.encoding.xml.encoding/asn1和其他库对 JSON.XML.ASN.1 和其他类型的标准的编码和解码提供了良好的支持,这里对使用最多 ...
- 安卓APP在线升级
安卓APP在线升级 通过IDHTTP组件在线下载APP到手机中,然后自动安装这个APP程序. 1)在线下载APP程序 需引用单元: {$IFDEF ANDROID} FMX.Helpers.Andro ...
- C# - ZIP 压缩流
C# - ZIP 压缩流 参考资料 https://docs.microsoft.com/en-us/dotnet/api/system.io.compression.ziparchive?view= ...
- Django 测试开发2
1.get方法和post方法 get方法 post方法 直接把method修改成post,报错如下,Django针对CSRF的保护措施是在生成的每个表单放置一个自动生成的令牌,通过这个令牌判断POS ...
- linux工程管理软件—make
一.make概述 make是一种代码维护工具make工具会根据makefile文件定义的规则和步骤,完成整个软件项目的代码维护工作.一般用来简化编译工作,可以极大地提高软件开发的效率. win ...
- mysql数据库分库分表(Sharding)(转)
mysql数据库切分 前言 通过MySQLReplication功能所实现的扩展总是会受到数据库大小的限制.一旦数据库过于庞大,尤其是当写入过于频繁,非常难由一台主机支撑的时候,我们还是会面临到扩展瓶 ...
- 真正解决方案:java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter
今天在使用JDK 12.0 环境下使用Hibernate 时候出现了这个错误,错误日志如下: 故障原因: JAXB API是java EE 的API,因此在java SE 9.0 中不再包含这个 Ja ...
- Cisco设备自动定时备份配置
前言 当我们管理的网络设备为个位数的时候,手动的把配置通过tftp方式copy出来还是可以的.但是当我们管理几十台甚至上百台(有点夸张,都这个级别了肯定用专业的运维软件或者开发运维平台进行管理)的时候 ...
- nginx在windows系统中如何启动、重启、停止
nginx在windows系统中如何启动.重启.停止 查看nginx的版本号:nginx -v 启动nginx:start nginx 快速停止或关闭nginx:nginx -s stop 正常停 ...
- PYTHON指定国内PIP源
一.LINUX: vi ~/.pip/pip.conf 输入内容: [global]index-url = http://pypi.douban.com/simple/[install]trusted ...