HDU - 6197 array array array (最长上升子序列&最长下降子序列)
题意:对于一个序列,要求去掉正好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个就好了。
- #include<cstdio>
- #include<cstring>
- #include<cstdlib>
- #include<cctype>
- #include<cmath>
- #include<iostream>
- #include<sstream>
- #include<iterator>
- #include<algorithm>
- #include<string>
- #include<vector>
- #include<set>
- #include<map>
- #include<stack>
- #include<deque>
- #include<queue>
- #include<list>
- #define lowbit(x) (x & (-x))
- const double eps = 1e-8;
- inline int dcmp(double a, double b){
- if(fabs(a - b) < eps) return 0;
- return a > b ? 1 : -1;
- }
- typedef long long LL;
- typedef unsigned long long ULL;
- const int INT_INF = 0x3f3f3f3f;
- const int INT_M_INF = 0x7f7f7f7f;
- const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
- const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
- const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
- const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
- const int MOD = 1e9 + 7;
- const double pi = acos(-1.0);
- const int MAXN = 100000 + 10;
- const int MAXT = 10000 + 10;
- using namespace std;
- int a[MAXN], dp[MAXN];
- int main(){
- int T;
- scanf("%d", &T);
- while(T--){
- int n, k;
- scanf("%d%d", &n, &k);
- for(int i = 0; i < n; ++i){
- scanf("%d", &a[i]);
- }
- memset(dp, INT_INF, sizeof dp);
- for(int i = 0; i < n; ++i){
- *lower_bound(dp, dp + n, a[i]) = a[i];
- }
- int tmp1 = lower_bound(dp, dp + n, INT_INF) - dp;
- if(n - tmp1 <= k){
- printf("A is a magic array.\n");
- }
- else{
- reverse(a, a + n);
- memset(dp, INT_INF, sizeof dp);
- for(int i = 0; i < n; ++i){
- *lower_bound(dp, dp + n, a[i]) = a[i];
- }
- int tmp2 = lower_bound(dp, dp + n, INT_INF) - dp;
- if(n - tmp2 <= k){
- printf("A is a magic array.\n");
- }
- else{
- printf("A is not a magic array.\n");
- }
- }
- }
- return 0;
- }
HDU - 6197 array array array (最长上升子序列&最长下降子序列)的更多相关文章
- hdu 6197 2017 ACM/ICPC Asia Regional Shenyang Online array array array【最长不上升子序列和最长不下降子序列】
hdu 6197 题意:给定一个数组,问删掉k个字符后数组是否能不减或者不增,满足要求则是magic array,否则不是. 题解:队友想的思路,感觉非常棒!既然删掉k个后不增或者不减,那么就先求数组 ...
- HDU 6197 array array array 2017沈阳网络赛 LIS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6197 题意:给你n个数,问让你从中删掉k个数后(k<=n),是否能使剩下的序列为非递减或者非递增 ...
- 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 4604 Deque(最长不下降子序列)
从后向前对已搜点做两遍LIS(最长不下降子序列),分别求出已搜点的最长递增.递减子序列长度.这样一直搜到第一个点,就得到了整个序列的最长递增.递减子序列的长度,即最长递减子序列在前,最长递增子序列在后 ...
- HDU 6357.Hills And Valleys-字符串非严格递增子序列(LIS最长非下降子序列)+动态规划(区间翻转l,r找最长非递减子序列),好题哇 (2018 Multi-University Training Contest 5 1008)
6357. Hills And Valleys 自己感觉这是个好题,应该是经典题目,所以半路选手补了这道字符串的动态规划题目. 题意就是给你一个串,翻转任意区间一次,求最长的非下降子序列. 一看题面写 ...
- HDU 1160 FatMouse's Speed (动态规划、最长下降子序列)
FatMouse's Speed Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1160 FatMouse's Speed(最长不下降子序列+输出路径)
题意: FatMouse believes that the fatter a mouse is, the faster it runs. To disprove this, you want to ...
随机推荐
- css中class后面跟两个类,这两个类用空格隔开
css中class后面跟两个类,这两个类用空格隔开,那么这两个类对这个元素都起作用,如果产生冲突,那么后面的类将替代前面的类.
- python随机函数.2020.2.26
随机生成函数: import random //首先要引用random模板 print(random.randint(0,9)) //random的语法 random.randint(0,9 ...
- 企业面试问题收集-ssm框架
springMVC 1) 简单介绍下你对springMVC的理解? Spring MVC Framework有这样一些特点: 1.它是基于组件技术的.全部的应用对象,无论控制器和视图,还是业务对 ...
- #P1099 树网的核 题解
题目描述 pdf 题解 这一题,刚开始看题目感觉好像很难,题目又长……一看数据范围,呵呵. 已经给出来这是个DAG,所以不用担心连通性的问题.那么怎么做呢? 朴素的做法是把树的直径的两个端点都统计出来 ...
- iOS沙盒目录简介、沙盒路径获取
一.沙盒的意义 出于安全的考虑,iOS系统的沙盒机制规定每个应用只能访问当前沙盒目录下面的文件.但是对于一些用户级别的数据,考虑到很多软件都需要使用其中的数据,用户可以通过对当前的软件授权,让当前的应 ...
- HTML的几个注意点
一.HTML 1.HTML5有哪些新特性?新增的标签有哪些? 新特性: 语义标签——语义化标签使得页面的内容结构化,见名知义 增强型表单——拥有多个新的表单 Input 输入类型.这些新特性提供了更好 ...
- HTML<head></head>中标签的含义
我们都知道,HTML的标签可以分为很多种,head 里面的我们称为元信息类标签,诸如title.meta.style.link.base.script这些,他们用来描述文档的一些基本信息. 1. ti ...
- 神机iPhone6停产,苹果产业链应该感谢它还是痛恨它?
据国内媒体报道,一些苹果上游供应商已经接到通知,iPhone6系列将会在5月底彻底停产,一时间,竟在网络上引发汹涌的怀念之情.iPhone6的特别之处在于它是苹果第一款大屏幕的智能手机,标志着库克彻底 ...
- 一、jsp和Servlet基础理论及jstl和EL表达式用法
1.题外话:使用JSP有近一年半的时间了,但是开发量不大.昨天部门突然让做个读取EXCLE文件,然后在前台页面进行展示.并通过点击查看按钮可以对每条明细记录进行跳转后进行详情查看,并按照页面原型进行页 ...
- jQuery加减
var num1 = 123; var num2=123; var sum = num1+num2; 结果是246; <input type="text" id=" ...