First Last Sorting

 

 给一个数字n,然后n行,每行给出一个数字 (在1-n之间)  求最少的操作次数

n - 最长的连续上升子序列

这道题应该做出来,毕竟之前类似的做过,难过。。。。

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 1e5 + 5;
int n,a[maxn],dp[maxn];
int ans;
signed main(){
    //freopen("in","r",stdin);
    ios::sync_with_stdio(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    for(int i = 1; i <= n; i++){
        dp[a[i]] = dp[a[i] - 1] + 1;
        ans = max(ans,dp[a[i]]);
    }
    cout << n - ans;
    return 0;
}
原文地址:https://www.cnblogs.com/xcfxcf/p/12577392.html