HUD 5773 LIS(最长上升序列)
***关于lower_bound()的用法参见:http://blog.csdn.net/niushuai666/article/details/6734403
lower_bound用法:函数lower_bound()在first和last中的前闭后开的区间进行二分查找,返回大于或等于val的第一元素的位置(位置是从零开始的)。如果所有元素都小于val,则返回last的位置。***
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<cctype>
#include<queue>
#include<vector>
#include<algorithm> using namespace std;
typedef long long LL;
#define N 101000
#define INF 0x3f3f3f int a[N], g[N], d[N]; int main()
{
int T, n, cas=1;
scanf("%d", &T); while(T--)
{
scanf("%d", &n);
for(int i=1; i<=n; i++)
{
g[i]=INF;
scanf("%d", &a[i]);
} int num, ans;
num=ans=0; for(int i=1; i<=n; i++)
{
if(a[i]==0)
{
num++;
continue;
}
a[i]-=num;//减去这个数前面零的个数,这样可以剔点一些数,为零的变换留有足够大的空间
int k=lower_bound(g+1, g+n+1, a[i])-g;
d[i]=k;
g[k]=a[i];
ans=max(ans, d[i]);
}
printf("Case #%d: %d\n", cas++, ans+num);
}
return 0;
}
HUD 5773 LIS(最长上升序列)的更多相关文章
- (LIS)最长上升序列(DP+二分优化)
求一个数列的最长上升序列 动态规划法:O(n^2) //DP int LIS(int a[], int n) { int DP[n]; int Cnt=-1; memset(DP, 0, sizeof ...
- hdu 5256 序列变换(LIS最长上升子序列)
Problem Description 我们有一个数列A1,A2...An,你现在要求修改数量最少的元素,使得这个数列严格递增.其中无论是修改前还是修改后,每个元素都必须是整数. 请输出最少需要修改多 ...
- XHXJ's LIS HDU - 4352 最长递增序列&数位dp
代码+题解: 1 //题意: 2 //输出在区间[li,ri]中有多少个数是满足这个要求的:这个数的最长递增序列长度等于k 3 //注意是最长序列,可不是子串.子序列是不用紧挨着的 4 // 5 // ...
- 算法设计 - LCS 最长公共子序列&&最长公共子串 &&LIS 最长递增子序列
出处 http://segmentfault.com/blog/exploring/ 本章讲解:1. LCS(最长公共子序列)O(n^2)的时间复杂度,O(n^2)的空间复杂度:2. 与之类似但不同的 ...
- POJ - 3903 Stock Exchange(LIS最长上升子序列问题)
E - LIS Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Descripti ...
- POJ 3903 Stock Exchange (E - LIS 最长上升子序列)
POJ 3903 Stock Exchange (E - LIS 最长上升子序列) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action ...
- POJ 1887 Testingthe CATCHER (LIS:最长下降子序列)
POJ 1887Testingthe CATCHER (LIS:最长下降子序列) http://poj.org/problem?id=3903 题意: 给你一个长度为n (n<=200000) ...
- [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
- [LeetCode] Longest Consecutive Sequence 求最长连续序列
Given an unsorted array of integers, find the length of the longest consecutive elements sequence. F ...
- POJ 2533 Longest Ordered Subsequence 最长递增序列
Description A numeric sequence of ai is ordered if a1 < a2 < ... < aN. Let the subsequenc ...
随机推荐
- 'parent.relativePath' of POM com.qbb:log_record_elegant:1.0-SNAPSHOT points at com.qbb:qiu_code instead of org.springframework.boot:spring-boot-starter-parent
完整的错误: 'parent.relativePath' of POM com.qbb:log_record_elegant:1.0-SNAPSHOT (F:\QbbCode\qiu_code\log ...
- django查询-列延迟加载only()、defer()
这玩意和sqlalchemy的几乎一样. only():只加载给定的列,其他列只有在使用时会发起二次查询 defer():不加载指定的列,刚好和only()相反. 实例: >>> r ...
- 【OpenCV】【Python】关于cv2.findContours()轮廓索引(编号)解析(RETR_TREE)
在打算自己实现二维码的定位的时候,看到了相关博文的关于cv2.findContours返回的层级信息来定位三个"回"字从而达到定位二维码的目的,但是返回的hierarchy中的层级 ...
- 基于源码去理解Iterator迭代器的Fail-Fast与Fail-Safe机制
原创/朱季谦 在Java编程当中,Iterator迭代器是一种用于遍历如List.Set.Map等集合的工具.这类集合部分存在线程安全的问题,例如ArrayList,若在多线程环境下,迭代遍历过程中存 ...
- Web测试基本思路:UI测试、功能测试和兼容性测试
关于网站测试的基本思路,希望对测试小白有所帮助. 一.UI测试 用户界面测试主要是拿待测网页和设计稿进行对比,主要主要以下4点: 1.注重细节: 这点最基本,就是对比是细心.细心再细心. 2.主要整体 ...
- 编译安装openssl-1.1.1和openssh-9.4
1.安装 openssl-1.1.1 先处理下opensll的版本,以免编译安装Openssh环境异常: yum remove openssl cd /opt wget https://www.ope ...
- kubernetes web管理页面安装(二)
参考文件: https://cloud.tencent.com/developer/article/1919416 参考命令: https://blog.51cto.com/smbands/49038 ...
- Spring Boot入坑-3-Maven简介
概述 Maven是一个自动化构建工具 能够将支持Maven项目的依赖包从远程仓库拉取到本地仓库,并进行依赖管理 项目中通过pom.xml来描述项目,对项目依赖进行管理与配置 给项目提供编译.打包.安装 ...
- 快速入门Mybatis完成基本CURD(注解实现)
一.什么是Mybatis? MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射. MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集. MyB ...
- 当创建statefulset资源后,k8s组件如何协作
本文分享自华为云社区<当创建StatefulSet后,k8s会发生什么?>,作者:可以交个朋友 . 一.StatefulSet介绍 StatefulSet 是用来管理有状态应用的工作负载对 ...