首页 > 其他 > 详细

First Last Sorting

时间:2020-03-26 21:35:27      阅读:74      评论:0      收藏:0      [点我收藏+]

技术分享图片

 

 技术分享图片

 

 给一个数字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;
}

 

First Last Sorting

原文:https://www.cnblogs.com/xcfxcf/p/12577392.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!