#include <bits/stdc++.h>
#define maxn 5005
#define INF 1e18
#define MOD 1000000007
typedef long long ll;
using namespace std;
int num[maxn];
int dfs(int l, int r, int pre){
if(r < l)
return 0;
int h = min_element(num+l, num+r+1) - num;
return min(r-l+1, dfs(l, h-1, num[h]) + dfs(h+1, r, num[h]) + num[h] - pre);
}
int main(){
// freopen("in.txt", "r", stdin);
int n;
scanf("%d", &n);
for(int i = 1; i <= n; i++)
scanf("%d", num+i);
printf("%d\n", dfs(1, n, 0));
return 0;
}
Codeforces Round #256 (Div. 2)-C. Painting Fence
最新推荐文章于 2022-12-22 23:05:36 发布