我上次来通过率是0.67%,没题解
2024-07-17 13:27:48
发布于:北京
32阅读
0回复
0点赞
#include <bits/stdc++.h>
#define MAX 405
using namespace std;
int n, m;
int a[MAX], f[MAX][MAX], s[MAX];
int main(){
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
s[i] = s[i-1]+a[i];
}
m++;
memset(f, 0x3f, sizeof(f));
f[0][0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= min(m, i); ++j) {
int mx = a[i];
for (int k = i-1; k >= 0; --k) {
f[i][j] = min(f[i][j], f[k][j-1]+mx*(i-k)-(s[i]-s[k]));
mx = max(mx, a[k]);
}
}
}
int ans = 0x3f3f3f3f;
for (int i = 0; i <= m; ++i) {
ans = min(ans, f[n][i]);
}
cout << ans << endl;
return 0;
}
这里空空如也
有帮助,赞一个