简单DP。
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <climits>
#define MAXN 105 int dp[][MAXN];
int a[]; int getMin(int a, int b) {
return a<b?a:b;
} int main() {
int n, max, min;
int i, j, k, r, tmp, ans;
int hire, salary, fire;
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
#endif
while (scanf("%d",&n)!=EOF && n) {
scanf("%d %d %d", &hire, &salary, &fire);
max = INT_MIN;
min = INT_MAX;
for (i=; i<=n; ++i) {
scanf("%d", &a[i]);
if (a[i] > max)
max = a[i];
if (a[i] < min)
min = a[i];
}
for (r=; r<=n; ++r) {
for (i=a[r]; i<=max; ++i) {
if (r == ) {
dp[r][i] = i*(hire+salary);
continue;
}
ans = INT_MAX;
for (j=a[r-]; j<=max; ++j) {
tmp = dp[r-][j] + i*salary;
if (j >= i) {
ans = getMin(ans, tmp+(j-i)*fire);
} else {
ans = getMin(ans, tmp+(i-j)*hire);
}
}
dp[r][i] = ans;
}
}
ans = INT_MAX;
for (i=a[n]; i<=max; ++i)
if (dp[n][i] < ans)
ans = dp[n][i];
printf("%d\n", ans);
} return ;
}