求一下最长数字连续上升的子序列长度,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. svn回滚

    有时会因为某些原因会错误提交某些文件: 1,官方版本库升级,自己的库代码也要跟着升级,但发现使用官方代码后有问题,代码需要回滚到可用的版本: 2,拷贝一个项目的代码到另外一个项目,把整个代码目录也拷贝 ...

  2. 用 gulp.spritesmith 自动化雪碧图

    一.安装nodejs之后,要设置两个环境变量 在 计算机右击属性---高级系统设置---高级---环境变量 打开窗口 新建2个环境变量,它们的值分别是nodejs根目录下的node_modules路径 ...

  3. PHP常用的预定义常量

    <?php echo 'PHP常用的预定义常量'.'<br><br>'; echo '当前php的版本为(PHP_VERSION):'.PHP_VERSION.'< ...

  4. 取distinct数据同时还取其他字段

    的 SELECT id,group_concat(distinct model) FROM tsdr_case group by model order by id

  5. VMware设置NAT网络

    很多初学者迷茫与如何实现虚拟机VMware与主机互联,这里小编介绍下简单实用的NAT网络. 工具/原料   VMware 方法/步骤   打开VMware,选择  编辑, 虚拟网络编辑器 默认情况下, ...

  6. myeclipse 之 快捷键

    简单记录一下,新装了个机器,win7系统,想设置一下自己习惯的快捷键 如:ctrl+alt+方向键,复制行,发现设置不上,原先的自带的也失效,设置一下ctrl+alt+其它键,ok可以使用,这说明某些 ...

  7. linux 守护进程创建流程

    #include <sys/stat.h> #include <fcntl.h> /* Bit-mask values for 'flags' argument of beco ...

  8. XTEA加密算法

    XTEA加密算法 #include <stdint.h> /* take 64 bits of data in v[0] and v[1] and 128 bits of key[0] - ...

  9. 视频录制SurfaceView

    package com.bw.videorecorder; import java.io.File;import java.io.IOException; import android.media.M ...

  10. java 接口的回调

    Example6_3.java interface ShowMessage { void 显示商标(String s); } class TV implements ShowMessage { pub ...