链接: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. SpringBoot性能优化之HikariCP连接池

    以前一直使用阿里Druid数据库连接池,这段时间听说有个号称速度最快.代码最简的后起之秀——HikariCP,于是动手实践一下 1.依赖如下: <?xml version="1.0&q ...

  2. 1222: 计算x^1+x^2+x^3+……+x^n的值

    #include <stdio.h>int main(){ int x,n,i,j; long long sum,g;while(scanf("%d%d",&x ...

  3. PAT (Advanced Level) Practice 1001-1005

    PAT (Advanced Level) Practice 1001-1005 PAT 计算机程序设计能力考试 甲级 练习题 题库:PTA拼题A官网 背景 这是浙大背景的一个计算机考试 刷刷题练练手 ...

  4. oracle的锁种类知识普及

    锁概念基础 数据库是一个多用户使用的共享资源.当多个用户并发地存取数据时,在数据库中就会产生多个事务同时存取同一数据的情况.若对并发操作不加控制就可能会读取和存储不正确的数据,破坏数据库的一致性. 加 ...

  5. 情人节到了,Postman 都脱单了,那你咧?

    前言 Postman 是一款API接口调试工具,做过 Web 接口或多或少应该接触过. 通过它可以完成 Http 接口的调试,测试同学也可以基于此做一些自动化测试.另外 Postman 还提供其他高级 ...

  6. ccf

    import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; public class MST { pu ...

  7. C# 接口和继承

    转:https://www.cnblogs.com/songhe123/p/9558545.html 接口是方法的抽象,如果不同的类有同样的方法,那么就应该考虑使用接口. 例1: using Syst ...

  8. HYSBZ_2002_分块

    http://www.lydsy.com/JudgeOnline/problem.php?id=2002 分块基础题,初次接触,很巧妙. OJ好像挂了,没法提交. #include<iostre ...

  9. CCF_ 201412-1_门禁系统

    水. #include<iostream> #include<cstdio> using namespace std; int main() { ],num[] = {}; c ...

  10. learn about sqlserver partitition and partition table 1

    Dear all, Let get into business, the partitions on sql server is very different with that on oracle. ...