链接:P3902

-----------------------------------------

这道题就是最长上升子序列的模板题,因为我们修改的时候可没说不能改成小数(暴力)

----------------------------------------

最长上升子序列有很多求法,这道题dp是不行的,TLE。

就要用nlogn的二分算法

---------------------------------------

这个算法是这样的,建立一个数组了,low,其中low[i]表示长度为i的上升子序列的结尾最小值

来考虑维护它,如果一个新数a[i]比low[最后一个]大,我们就low[++low的长度]=a[i];

else,考虑一下,如果结尾的元素越小,他的潜力就越大,所以贪心的考虑一下,为什么不让它去给low增加点潜力呢?

找到第一个大于等于a[i]的low,并且更新它。

这样就可以在nlogn内求出了

----------------------------------------

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn=;
const int inf=0x7f7f7f7f;
int n,ans;
long long low[maxn],a[maxn];
int main(){ cin>>n;
for(int i=;i<=n;++i)
{
cin>>a[i];
low[i]=inf;
}
low[]=a[];
ans=;
for(int i=;i<=n;++i){
if(a[i]>low[ans])
low[++ans]=a[i];
else
low[lower_bound(low+,low+ans+,a[i])-low]=a[i];
}
cout<<n-ans;
return ;
}

Ac

P3902 递增的更多相关文章

  1. 洛谷 P3902 递增

    P3902 递增 题目描述 现有数列A_1,A_2,\cdots,A_NA1​,A2​,⋯,AN​,修改最少的数字,使得数列严格单调递增. 输入输出格式 输入格式: 第1 行,1 个整数N 第2 行, ...

  2. JDOJ 2157 Increasing

    洛谷 P3902 递增 洛谷传送门 JDOJ 2157: Increasing JDOJ传送门 Description 数列A1,A2,--,AN,修改最少的数字,使得数列严格单调递增. Input ...

  3. 【树状数组】【P3902】 递增

    传送门 Description 给你一个长度为\(n\)的整数数列,要求修改最少的数字使得数列单调递增 Input 第一行为\(n\) 第二行\(n\)个数代表数列 Output 输出一行代表答案 H ...

  4. [LeetCode] Increasing Triplet Subsequence 递增的三元子序列

    Given an unsorted array return whether an increasing subsequence of length 3 exists or not in the ar ...

  5. [LeetCode] Longest Increasing Path in a Matrix 矩阵中的最长递增路径

    Given an integer matrix, find the length of the longest increasing path. From each cell, you can eit ...

  6. [LeetCode] Longest Increasing Subsequence 最长递增子序列

    Given an unsorted array of integers, find the length of longest increasing subsequence. For example, ...

  7. SQLSERVER如何使用递增排序的GUID做主键

    场景: 产品表数据量较大想用Guid做表的主键,并在此字段上建立聚簇索引. 因为Guid是随机生成的,生成的值大小是不确定的,每次生成的数可能很大,也可能很小.这样会影响插入的效率 1.NEWSEQU ...

  8. 51nod1134(最长递增子序列)

    题目链接: https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1134 题意: 中文题诶~ 思路: 直接暴力的话时间复杂度为 ...

  9. [LintCode] Longest Increasing Subsequence 最长递增子序列

    Given a sequence of integers, find the longest increasing subsequence (LIS). You code should return ...

随机推荐

  1. 第三次作业:使用Packet Tracer分析TCP连接的建立与释放过程

    0 个人信息 张樱姿 201821121038 计算1812 1 实验目的 使用路由器连接不同的网络 使用命令行操作路由器 通过抓取HTTP报文,分析TCP连接建立的过程 2 实验内容 使用Packe ...

  2. 死磕java(2)

    java数据类型 boolean --true--false byte --8位 short --16位 int --32位 long --64位 char float --32位 double -- ...

  3. python 函数3(模块)

    1.将函数存储在模块中 1.1.导入整个模块 要将函数导入,得先创建模块,模块 是扩展名为.py的文件,包含要导入到程序中的代码. 首先定义编写一个.py的文件,命名为pizza.py,代码如下: d ...

  4. 使用ClouderaManager管理的HBase的RegionServer无法启动(启动失败)的问题

    问题概述 "新冠期间"远程办公,需要重新搭建一套ClouderaManager(CM)开发环境,一位测试同事发现HBase的RegionServer无法启动,在CM界面上启动总是失 ...

  5. Java中的8种基本数据类型

    JAVA中的8种基本数据类型:byte short int long float double char boolean 特别说明: 1)char类型占2个字节,可以表示汉字.汉字和英文字符都占2个字 ...

  6. Codeforces_714_A

    http://codeforces.com/problemset/problem/714/A 水,注意K的值. #include <iostream> using namespace st ...

  7. 剑指offer刷题笔记

    删除链表中重复的结点:较难 在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针. 例如,链表1->2->3->3->4->4- ...

  8. 【译文连载】 理解Istio服务网格(第一章 概述)

    书籍英文版下载链接为 https://developers.redhat.com/books/introducing-istio-service-mesh-microservices/,作者 Burr ...

  9. 【WPF学习】第四十六章 效果

    WPF提供了可应用于任何元素的可视化效果.效果的目标是提供一种简单的声明式方法,从而改进文本.图像.按钮以及其他控件的外观.不是编写自己的绘图代码,而是使用某个继承自Effect的类(位于System ...

  10. python xlrd操作

    python里面的xlrd模块详解(一)   那我就一下面积个问题对xlrd模块进行学习一下: 1.什么是xlrd模块? 2.为什么使用xlrd模块? 3.怎样使用xlrd模块? 1.什么是xlrd模 ...