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 ...
随机推荐
- HD1269迷宫城堡(有向图 && 划分连通块)
迷宫城堡 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- 强大的css3
强大的css3 我们知道,这几年来智能手机的高速发展使得人们使用移动端上网的时间和人数已经超过了PC端.例如在2015年,就中国电商而言,各电商平台在移动端持续发力,移动端购物占比不断攀升,双11期间 ...
- linux第一面
随着Linux应用的扩展许多朋友开始接触Linux,根据学习Windwos的经验往往有一些茫然的感觉:不知从何处开始学起.作为一个 Linux系统管理员,我看了许多有关Linux的文档和书籍,并为学习 ...
- Get&Post登录
#import "MJViewController.h" @interface MJViewController () @property (weak, nonatomic) IB ...
- css009 装饰网站的导航
css009 装饰网站的导航 1. 选择定义样式的链接 1.连接的状态: A.未访问 a:link{C;} B.已访问 a:visited{ color : red; } C.鼠标 ...
- java实现Haffman编码
1.先创建一个树节点类(泛型类),为了方便使用集合的排序方法,泛型类要实现泛型接口Comparable,代码如下 package com.hjp.huffman; /** * Created by J ...
- python 内建函数setattr() getattr()
python 内建函数setattr() getattr() setattr(object,name,value): 作用:设置object的名称为name(type:string)的属性的属性值为v ...
- (新手向)基于Bootstrap的简单轮播图的手机实现
个人电脑里存了不少适合手机欣赏的图片,但是放手机里看是件很占据资源的事.鉴于家里有一台电脑经常开着,正好用来做家庭局域网共享,于是笔者就设想通过一种比较简单环保的思路.通过手机访问电脑内的图片. 首先 ...
- ecshop默认配置
手机端 1.C, 系统默认所有配置 输出:print_r(C())
- JS获取checkbox的个数
本文算是转载自网络,当时用了他的函数,现在想总结一下,但忘了原文地址了 ================================================================ ...