codeforce 606C - Sorting Railway Cars

题意:给你一串数,没个数只能往前提到首位,或则往后放末尾。问最少步骤使操作后的序列成上升序列。

思路:最长连续子序列。

 1 #include<iostream>
 2 #include<stdio.h>
 3 #include<stdlib.h>
 4 #include<memory.h>
 5 #include<string.h>
 6 #include<algorithm>
 7 #include<cmath>
 8 const int N = 30;
 9 const int inf=-100000;
10 using namespace std;
11 
12 int main()
13 {
14     int n;
15     int h[100010];
16     int dp[100010];
17     int a[100010];
18     scanf("%d",&n);
19     for(int i=1; i<=n; i++)
20     {
21         scanf("%d",&a[i]);
22     }
23     int ans=0;
24     for(int i=1; i<=n; i++)
25     {
26         h[a[i]]++;
27         if(h[a[i]-1])
28             dp[a[i]]=dp[a[i]-1]+1;
29         else
30             dp[a[i]]=1;
31         ans=max(dp[a[i]],ans);
32     }
33     cout<<n-ans<<endl;
34     return 0;
35 }
View Code

 

转载于:https://www.cnblogs.com/ITUPC/p/5038787.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值