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 ...
随机推荐
- 使用WebService和不使用WebService哪个速度更快哪个更安全
- SSH项目与SSM项目的进入首页的方法
SSH项目中: jsp页面一般都是存放在WEB-INF下面的目录下,这样我们就不能直接访问到这些jsp页面了,保证了页面的安全性. 在struts的管理中,是利用action来实现页面的跳转,进入in ...
- Yocto开发笔记之《Tip-设置程序开机启动》(QQ交流群:519230208)
QQ群:519230208,为避免广告骚扰,申请时请注明 “开发者” 字样 IMX6UL,转载请注明出处 ============================================== ...
- 每天一个linux命令:route命令
Linux系统的route命令用于显示和操作IP路由表(show / manipulate the IP routing table).要实现两个不同的子网之间的通信,需要一台连接两个网络的路由器,或 ...
- easyUI-combotree的本地数据导入
一.页面内容: <div style="margin:10px 0"> <a href="javascript:void(0)" class= ...
- cmd chcp命令切换字符格式UTF8
cmd chcp命令切换字符格式 命令介绍: chcp 65001 #换成utf-8代码页 chcp 936 #换成默认的gbk chcp 437 #美国英 ...
- ecshop循环foreach,iteration,key,index
转载: 最近刚接触ecshop不久,感觉是非常的强大,做商城网站,整个流程都差不多搞好了,就是支付流程要自己完善完善,不过也有不足,文章功能还不够好. 通过几天的应用,总结出了ec模版中foreach ...
- Django笔记-MySQL初次使用设置
以下为个人学习时的笔记,正在完善中........... [1]启动服务 [root@bogon /]# service mysqld start正在启动 mysqld: [确定] [root@bog ...
- Microsoft.Web.Redis.RedisSessionStateProvider
https://github.com/Azure/aspnet-redis-providers https://www.nuget.org/packages/Microsoft.Web.RedisSe ...
- .NET4.0 __doPostBack未定义
方法一.浏览器设置成兼容模式. 方法二.安装服务器版的.Net40的补丁.http://download.csdn.net/detail/5653325/6642051 方法三.点击VS的工具菜单-- ...