482. 合唱队形

Powered by:NEFU AB-IN

Link

文章目录

482. 合唱队形

题意

略 (形成山丘式的队形,最少提几个人)

思路

前后各做一次LIS(必须是dp)

fi 就表示以i为结尾的正序的LIS

gi 就表示以i为结尾的逆序的LIS
*

代码

cpp 复制代码
#include <bits/stdc++.h>
using namespace std;
#define int long long
#undef int

#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define IOS                                                                                                            \
    ios::sync_with_stdio(false);                                                                                       \
    cin.tie(nullptr);                                                                                                  \
    cout.tie(nullptr)
#define DEBUG(X) cout << #X << ": " << X << '\n'

const int N = 1e5 + 10, INF = 0x3f3f3f3f;

int a[N], f[N], g[N];

signed main() {
    //freopen("Tests/input_1.txt", "r", stdin);
    IOS;

    int n;
    cin >> n;
    for (int i = 1; i <= n; ++ i) cin >> a[i];


    for (int i = 1; i <= n; ++ i) {
        f[i] = 1;
        for (int j = 1; j < i; ++ j) {
            if (a[j] < a[i]) f[i] = max(f[i], f[j] + 1);
        }
    }


    for (int i = n; i; -- i) {
        g[i] = 1;
        for (int j = n; j > i; -- j)
            if (a[j] < a[i]) g[i] = max(g[i], g[j] + 1);
    }

    int mx = 0;
    for (int i = 1; i <= n; ++ i) {
        mx = max(mx, f[i] + g[i] - 1);
    }

    cout << n - mx;

    return 0;
}
相关推荐
不会就选b6 小时前
算法日常・每日刷题--<贪心>14
算法
mmmmath_38 小时前
LeetCode.541.反转字符串II
数据结构·算法·leetcode
Navigator_Z8 小时前
LeetCode //MySQL - 1251. Average Selling Price
c语言·算法·leetcode
醇氧9 小时前
MySQL 8.0 系统表损坏与引擎转换故障排查实战
数据结构·算法
大熊背10 小时前
《Color constancy by characterization of illumination chromaticity》之色度色域最大化算法(二)
算法·白平衡·色度·色温
钓鱼的肝10 小时前
梳理(1-5)
c++·经验分享·笔记·算法·青少年编程
HZZD_HZZD10 小时前
CSDN_批发市场水电漏损归因算法LAM的原理与落地
嵌入式硬件·物联网·算法
shirsl12 小时前
算法 Day 5 树 / 二叉树 + DFS
数据结构·python·算法
木子算法13 小时前
非凸、离散、还耦合:论文里的求解方法是一条四步流水线
人工智能·算法·目标跟踪