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 ...
随机推荐
- Js里面的强制类型转换
js 和 PHP语言一样是弱类型语言.近期我也在看C语言,并没有传说中那么难,既是书中一再强调的指针部分,也没有那么夸张.至少是理论和语法理解起来不是很难.看起来凡是什么东西,不要总是被别人的话迷惑了 ...
- Linux学习之CentOS--CentOS6.下Mysql数据库的安装与配置
跟着配置,顺利配置完成 http://www.cnblogs.com/xiaoluo501395377/archive/2013/04/07/3003278.html
- zabbix 安装
php+nginx+mysql+zabbix 官方https://www.zabbix.com/documentation/3.0/manual/installation/install 1.安装依赖 ...
- Objective-C学习笔记之for( int )机制
NSArray *myArray = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4&q ...
- 利用百度开发者中心的api实现地图及周边的搜索
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- Linux中设置定期备份oracle数据库
昨天装好了oracle,今天尝试一下自动备份,我这两天装linux和oracle的目的就是这个. 如果是sql server,定期备份可以利用sql server的management studio来 ...
- AspectJ基础学习之三HelloWorld(转载)
AspectJ基础学习之三HelloWorld(转载) 一.创建项目 我们将project命名为:aspectjDemo.然后我们新建2个package:com.aspectj.demo.aspect ...
- Java数据结构——有序链表
//================================================= // File Name : SortedList_demo //--------------- ...
- CodeForces 716B Complete the Word
题目链接:http://codeforces.com/problemset/problem/716/B 题目大意: 给出一个字符串,判断其是否存在一个子串(满足:包含26个英文字母且不重复,字串中有‘ ...
- 网页js,DIV全屏布局
<script type="text/javascript"> $(document).ready(function(){ findDimensions(); }); ...