题意:

  有一个长度为n的数组a。你可以删除一个位置之后进行操作,一次操作可以把任意位置上的数字变成任意的值,问最少需要多少操作能使得数列变成严格上升的。

  n<=200000

分析:

  如果没有删除,那是个经典问题,我们只要对{ai-i}求最长不降子序列就行了

  现在有个删除,若删除一个元素,那么它后面那些元素的位权-1,所以对于每个位置我们关心的只是它的位权是i还是i-1

  于是考虑dp,dp[0][i][j]表示做完了前i个位置,之前没有删除元素,长度为j的不降子序列最后一位的最小值,dp[1][i][j]同理

  考虑转移,dp[0][i]=(a[i]-i)二分插入dp[0][i-1],dp[1][i]的每个位置=min((a[i]-i+1)二分插入dp[1][i-1],  dp[0][i-1])

  其中dp[1][i][j]=min(dp[1][i][j],dp[0][i-1][j])这个转移很不好,是O(n)的,其它转移都是O(logn)的是可以接受的

  仔细观察发现,实际上只有上一次的a[i-1]-(i-1)插入的位置可能会更新此时的dp[1][i],所以这个转移其实可以做到O(1)

  

 #include<bits/stdc++.h>
using namespace std;
const int maxn=2e5,inf=2e9;
int dp[][maxn+];
int a[maxn+];
int n,len0,len1;
int main()
{
scanf("%d",&n);
for(int i=;i<=n;++i) scanf("%d",&a[i]);
for(int i=;i<=n;++i) dp[][i]=dp[][i]=inf;
int last=;
dp[][]=a[]-,len0=;
for(int i=;i<=n;++i)
{
int p=upper_bound(dp[]+,dp[]+len1+,a[i]-i+)-dp[];
dp[][p]=a[i]-i+;
len1=max(len1,p); dp[][last]=min(dp[][last],dp[][last]);
len1=max(len1,last); p=upper_bound(dp[]+,dp[]+len0+,a[i]-i)-dp[];
dp[][p]=a[i]-i;
last=p;
len0=max(len0,p);
}
printf("%d\n",min(n-len0,n-len1-));
return ;
}

  

codeforces 946G的更多相关文章

  1. Codeforces 946G Almost Increasing Array (树状数组优化DP)

    题目链接   Educational Codeforces Round 39 Problem G 题意  给定一个序列,求把他变成Almost Increasing Array需要改变的最小元素个数. ...

  2. [Codeforces 946G]Almost Increasing Array

    Description 题库链接 给你一个长度为 \(n\) 的序列 \(A\) .现在准许你删除任意一个数,删除之后需要修改最小的次数使序列单调递增.问最小次数. \(1\leq n\leq 200 ...

  3. Almost Increasing Array CodeForces - 946G (dp)

    大意: 定义几乎递增序列为删除不超过一个数后序列严格递增. 给定序列, 求最少改变多少个数能变为几乎递增序列. 跟hdu5256类似,

  4. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  9. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

随机推荐

  1. (4)JSTL的SQL标签库

    jstl的SQL标签库 SQL tag Library中的标签用来提供在 JSP 页面中可以与数据库进行交互的功能Database access标签库有以下6组标签来进行工作: <sql:set ...

  2. MySQL插入SQL语句后在phpmyadmin中注释显示乱码

    自己写一个建一个简单的数据表,中间加了个注释,但是用PHPmyadmin打开后发现注释不对. 就先查询了一下sql 语句 发现SQL 语句并没有问题,感觉像是显示编码的问题,就先用set names ...

  3. 身份证号正则校验(js校验+JAVA校验)

    js校验身份证号[15位和18位] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 3 ...

  4. apache 报413

    http://www.hostlift.com/apache/modsecurity-request-body-content-length-is-larger-than-the-configured ...

  5. iOS面试集锦3

    1.写一个NSString类的实现 + (id)initWithCString:(c*****t char *)nullTerminatedCString encoding:(NSStringEnco ...

  6. Java 的访问权限

    public>protected>默认(包访问权限)>private,因为protected除了可以被同一包访问,还可以被包外的子类所访问

  7. Windows10系统可以禁止的服务(按名称排序)

    1.Application LayerGateway Service(Windows必须禁止的10项服务) 2.Bluetooth Handsfree Service(没有蓝牙的用户可以关闭) 3.B ...

  8. Python发行版(编译器)

    一.Python编译器简介 根据实现Python编译器语言一般分为以下几种: 1.1.CPython 标准的Python,解释型编译器. Python:标准的CPython版本,即官方发布版本. IP ...

  9. python中split()函数讲解

    本文讲述的是string.split(s[, sep[, maxsplit]]),针对string类型的split()函数.它主要是切割字符串,结果返回由字符串元素组成的一个列表,具体怎么使用看下面的 ...

  10. BZOJ 2295: [POJ Challenge]我爱你啊

    由于是子序列,那么难度就在于读入 #include<cstdio> #include<algorithm> #include<cstring> using name ...