求一下最长数字连续上升的子序列长度,n-长度就是答案

O(n)可以出解,dp[i]=dp[i-1]+1,然后找到dp数组最大的值。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int INF=0x7FFFFFFF;
const int maxn=+;
int dp[maxn];
int n,x; int main()
{
while(~scanf("%d",&n))
{
memset(dp,,sizeof dp);
for(int i=; i<=n; i++)
{
scanf("%d",&x);
dp[x]=dp[x-]+;
}
int ans=-INF;
for(int i=; i<=n; i++)
if(dp[i]>ans)
ans=dp[i];
printf("%d\n",n-ans);
}
return ;
}

CodeForces 605A Sorting Railway Cars的更多相关文章

  1. CodeForces 605A Sorting Railway Cars 思维

    早起一水…… 题意看着和蓝桥杯B组的大题第二道貌似一个意思…… 不过还是有亮瞎双眼的超短代码…… 总的意思呢…… 就是最长增长子序列且增长差距为1的的…… 然后n-最大长度…… 这都怎么想的…… 希望 ...

  2. Codeforces 335C Sorting Railway Cars

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  3. [Codeforces 606C]Sorting Railway Cars

    Description An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the n ...

  4. CodeForces 606C Sorting Railway Cars(最长连续上升子序列)

    Description An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the n ...

  5. cf 605A Sorting Railway Cars 贪心 简单题

    其实就是求总长度 - 一个最长“连续”自序列的长度 最长“连续”自序列即一个最长的lis,并且这个lis的值刚好是连续的,比如4,5,6... 遍历一遍,贪心就是了 遍历到第i个时,此时值为a[i], ...

  6. Codeforces Round #335 (Div. 2) C. Sorting Railway Cars 动态规划

    C. Sorting Railway Cars Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/conte ...

  7. Codeforces Round #335 (Div. 2) C. Sorting Railway Cars 连续LIS

    C. Sorting Railway Cars   An infinitely long railway has a train consisting of n cars, numbered from ...

  8. Codeforces 606-C:Sorting Railway Cars(LIS)

    C. Sorting Railway Cars time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  9. Codeforces Round #335 (Div. 2) C. Sorting Railway Cars

    C. Sorting Railway Cars time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

随机推荐

  1. Linux中nmon的安装与使用【转】

      一.下载nmon. 根据CPU的类型选择下载相应的版本:http://nmon.sourceforge.net/pmwiki.php?n=Site.Downloadwget http://sour ...

  2. php5.6之后的版本使用curl以@+文件名的方式上传文件无效的解决版本

    使用curl上传文件使用file=@文件路径的方式,在php5.6以后的版本中无法使用了 官方文档给出明确解释 如果需要支持的话,可以将CURLOPT_SAFE_UPLOAD设置为false 或者使用 ...

  3. LNMP环境的安装配置

    0.安装必要的依赖软件 如果已经安装了可能会进行升级,版本完全一致则不会进行任何操作. yum -y install bzip2-devel curl-devel freetype-devel gcc ...

  4. 将decimal类型的数据转成2.12这样价钱的显示方式

    UnitPrice = string.Format("{0:.00}", m.UnitPrice),

  5. oracle恢复一个数据表的方法

    今天提交给客户方一个sql脚本去跟新历史数据,结果客户那边的部署人员犯了一个错误,直接拿系统账号去部署,结果第一段代码没有执行成功,结果第二段代码却执行成功了,并且已经提交了的,....由于事前没有备 ...

  6. thunk技术

    Thunk : 将一段机器码对应的字节保存在一个连续内存结构里, 然后将其指针强制转换成函数. 即用作函数来执行,通常用来将对象的成员函数作为回调函数. #include "stdafx.h ...

  7. C: define many functions using predefine..

    /* Defines COUNTER. There must be exactly one such definition at file scope * within a program. */ # ...

  8. Apache + PHP in Windows XP (to add SQLite)

    Firstly, Winxp do not support VC11+, so choose Apache packs compiled under VC10-. Before installatio ...

  9. POJ3321/Apple tree/(DFS序+线段树)

    题目链接 Apple Tree Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9692 Accepted: 3217 Descr ...

  10. js框架——angular.js(2)

    1. 模块的利用扩充 模块的名称也可以当做变量使用,例如: <body ng-app> <label><input type="checkbox" n ...