First Last Sorting

First Last Sorting

 

 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/hazelxcf/p/12577392.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;

也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬

    First Last Sorting

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/337994

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年3月1日 下午11:23
下一篇 2023年3月1日 下午11:23

相关推荐