Task

 

 

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int maxn = 3e3 + 10;
int n,a[maxn];

int solve(int l,int r){
    int minn = 1e9 + 10;
    for(int i = l; i <= r; i++)
        minn = min(minn,a[i]);
    int ans = minn;
    int pre = l;
    for(int i = l; i <= r; i++){
        a[i] -= minn;
        if(!a[i]){
            ans += solve(pre,i - 1);
            pre = i + 1;
        }
    }
    if(pre != r + 1) ans += solve(pre,r);
    return min(ans,r - l + 1);
}
signed main(){
   // freopen("in","r",stdin);
    ios::sync_with_stdio(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> a[i];
    cout << solve(1,n);
    return 0;
}
View Code

 

posted @ 2020-05-02 19:43  Hazelxcf  阅读(130)  评论(0编辑  收藏  举报