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 ...
随机推荐
- Windows平台下Java,tomcat安装与环境配置
问题描述:在Windows下面做Java web相关的项目的时候,Java和tomcat是基础,这里记载一下Java环境的配置以及tomcat的安装和配置. 使用工具:Windows.jdk安装包.t ...
- [原][OSG][osgEarth]osgEarth例子程序简介
1.osgearth_graticule:生成经纬线. 2.osgearth_annotation:各类标注(点.线.面.模型.文本等). 3.osgearth_city:加载一个城市三维模型,可以浏 ...
- topcoder srm 633 div1
problem1 link 如果两个循环之内可以跳完,那么我们只要让这些步数之内的数字组成两个数字$p,q,p\leq q$,使得$p,q,x$组成三角形即可($p+q\geq x,p+x\geq q ...
- antd ——按钮
<ButtonGroup> <Button type="primary" htmlType="submit" onClick={this.ha ...
- iOS-代理设计模式delegate和protocol
充当代理的步骤: 首先要明确谁请别人代理,谁当别人的代理 1> 请代理三部曲: 1 写一个协议protoc,把自己不方便做的事列出来(@protocol studentDelegate < ...
- (CVE-2016-5195)脏牛本地提权
简要分析 该漏洞具体为,get_user_page内核函数在处理Copy-on-Write(以下使用COW表示)的过程中,可能产出竞态条件造成COW过程被破坏, 导致出现写数据到进程地址空间内只读内存 ...
- 基于MSP430G2231实现多路数据采集器
基于MSP430G2231实现多路数据采集器 声明:引用请注明出处http://blog.csdn.net/lg1259156776/ 系列博客说明:此系列博客属于作者在大三大四阶段所储备的关于电子电 ...
- php 字典升序从小到大方法
/* 字典升序*/ function formatParaMap($paraMap) { $buff = ""; ksort($paraMap); foreach ($paraMa ...
- Supported orientations has no common orientation with the application, and [UIAlertController shouldAutorotate] is returning YES
某一个页面横屏时会出现崩溃的问题描述,原因是当你在AppDelegate中返回的设备方向是UIInterfaceOrientationMaskLandscapeLeft.但是你在视图控制器中返回支持自 ...
- talend工具通过关键字来取得text文本中的数据
问题描述: 在文件夹中有多个text文本,通过关键字来取得text文本里面我所需要的数据,并出力到Excel里面.取得的数据,在text文本里面可能是多行的存在,并且在Excel里面是一行的存在. 解 ...