codeforce 606C

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

思路:最长连续子序列。

 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