Codeforces Round #335 Sorting Railway Cars 动态规划
题目链接:
http://www.codeforces.com/contest/606/problem/C
一道dp问题,我们可以考虑什么情况下移动,才能移动最少。很明显,除去需要移动的车,剩下的车,一定是相差为1的递增序列,而且这个序列一定也是最长的,例如4 1 2 5 3, 4 5是需要移动的,不移动的序列是1 2 3,所以我们只要求出这一最长的递增序列,用n去减就可以了。
dp[i]是以i为结尾,最长的递增序列,所以dp[i] = dp[i-1]+1,求最大即为所求结果。
#include<stdio.h>
#include<algorithm>
#define maxn 100005
using namespace std;
int a[maxn],dp[maxn];
int main(){
int n;
scanf("%d",&n);
for(int i = ;i<=n;i++){
scanf("%d",&a[i]);
}
int ans = ;
for(int i = ;i<=n;i++){
dp[a[i]] = dp[a[i]-]+;
ans = max(ans,dp[a[i]]);
}
printf("%d\n",n-ans) ;
return ;
}
Codeforces Round #335 Sorting Railway Cars 动态规划的更多相关文章
- 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 ...
- CF#335 Sorting Railway Cars
Sorting Railway Cars time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #335 (Div. 2)
水 A - Magic Spheres 这题也卡了很久很久,关键是“至少”,所以只要判断多出来的是否比需要的多就行了. #include <bits/stdc++.h> using nam ...
- A. Sorting Railway Cars
A. Sorting Railway Cars time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Codeforces Round #335 (Div. 2) C
C. Sorting Railway Cars time limit pe ...
- Codeforces 335C Sorting Railway Cars
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
随机推荐
- centos 搭建git服务器
centos 6搭建git服务器 安装 rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-6.noarch.rpm yum ins ...
- uC/OS-II互斥信号(OS_mutex)块
/*************************************************************************************************** ...
- 签名有元程序集 Signed Friend Assemblies
下面的例子演示了创建签名程序集和有元程序集.这就要求两个程序集都是强命名,在下面的例子中,两个程序集都用了同一个秘钥,也可以用不同的秘钥. 1. 生成秘钥, 这个在前面的博客中有说明,生成秘钥文件sn ...
- 删除elasticsearch索引脚本
只保留七天的索引 shell版 #!/bin/bash #hexm@ #只保留一周es日志 logName=( -nginxaccesslog -nginxerrorlog -phperrorlog ...
- 有了这个,再也不用每次连新机器都要设置secure crt属性了
我连服务器用的是secure crt,每次ssh新服务器的时候都得手动设置字符编码和背景颜色,今天问了旁边的开发原来可以全局设置,以后连服务器的时候就再也不用手动设置相关属性了.步骤如下: 一开始点击 ...
- Light Pre-Pass相关链接
Key Words: Light Pre-Pass, Deferred Lighting http://mquandt.com/blog/2010/03/light-pre-pass-round-2/ ...
- WebApp基础01-设置读取assets目录下文件
要读取assets下的目录,只需要修改三个地方即可 1.res/layout/activity_main.xml 2.AndroidManifest.xml 3.src\com\example\lcy ...
- XtraFinder到底好在哪里(标签、隐藏文件、路径拷贝与显示、从这里启动)
类似Chrome的标签 自定义工具栏可添加一个快速显示与隐藏当前目录隐藏文件的功能 拷贝路径 cd 到当前目录这个功能跟PathFinder7类似 当然还有其他很多功能,比如这个返回上级目录,
- sql server 使用for xml path 将1列多行转换为字符串连接起来,俗称 sql 合并字符
由于项目的原因,需要将一些记录分类汇总,但还要列出相关的明细,这样的需求我还是第一次遇到,蛋疼了,还是请求一下度娘吧.搜索一番还是有结果,请看以下例子: create table tb ([id] i ...
- string.replace正则表达式说明
str.replace(reg,function($0,$1,$2...,index,str){ }); $0: 匹配模式的字符串$1...: 匹配模式子表达式的字符串,0个或多个,个数取决于子表达式 ...