求一下最长数字连续上升的子序列长度,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. linq any() all() 返回true 或者false

    一.any()只要有一个符合条件就返回true static void Main(string[] args) { //any 有符合条件的就返回true ,,,,,,,,,}; ); Console ...

  2. Response.Flush()

    Response.Buffer=True就是在缓存网页 访问网站一般是程序直接输出网页结果,或从缓存中读取网页结果2种方式.两种方式在速度上是有差异的 设置 Response.Buffer = Tru ...

  3. display:table表格合并单元格

    直接上代码: <%@ page language="java" contentType="text/html; charset=UTF-8" pageEn ...

  4. MFC DLL中导出函数模板

    //my.h struct AFX_EXT_CLASS B { }; struct AFX_EXT_CLASS C { }; class AFX_EXT_CLASS A { public: templ ...

  5. jquery 中 $('div','li')

    要搞清楚$('div','li') 和 $('div , li') 和 $('div li') 区别$('div','li')是$(子,父),是从父节点里找子,而不是找li外面的div $('div ...

  6. getByClassName2016/4/21

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  7. Mac机上安装虚拟机

    1.首先要下载虚拟机VMware.网址http://pan.baidu.com/share/init?shareid=1519279671&uk=1434905687,连接该网址,下载里边的这 ...

  8. 微软企业库3.1DIY编译使用(数据库连接符写在企业库DLL里)

    1.在winform项目app.config文件中去掉"PublicKeyToken=b03f5f7f11d50a3a"(不然无法加载使用新编译的企业库DLL文件) 2.在企业库所 ...

  9. HDU 3691 Nubulsa Expo

    无向图的最小割.套了个模板. #include<iostream> #include<cstdio> #include<cstring> #include<a ...

  10. 使用JavaCV/OpenCV抓取并存储摄像头图像

    http://blog.csdn.net/ljsspace/article/details/6702178  分类: 图形图像(3)  版权声明:本文为博主原创文章,未经博主允许不得转载. 本程序通过 ...