很容易发现后面的数组尽量不要动,所以从后考虑贪心,对于每一个i,贪心到小于a[i+1]即可整体复杂度o(n)
#include <bits/stdc++.h>
using namespace std;
小红拿到了一个数组,他每次操作可以选择任意一个元素x使其变成x(向下取整)。
小红想知道,使得该数组变成非降序,需要至少操作多少次?
Scan the QR code below with WeChat to sign in
First-time scan will create your account automatically
请使用微信扫描下方二维码完成注册