### Problem

A project manager wants to determine the number of the workers needed in every month. He does know the minimal number of the workers needed in each month. When he hires or fires a worker, there will be some extra cost. Once a worker is hired, he will get the salary even if he is not working. The manager knows the costs of hiring a worker, firing a worker, and the salary of a worker. Then the manager will confront such a problem: how many workers he will hire or fire each month in order to keep the lowest total cost of the project.

### Analysis

dp[i][j]为第i个月雇佣j个人的最小总花费，每个月的雇佣的人数的上限是所有月份的最大值。转移计算一下就好了…

### Code

```#include <bits/stdc++.h>
using namespace std;

const int inf = 0x3f3f3f3f;
int N, v[15], dp[15][7777];

int main() {
while(scanf("%d", &N), N) {
int A, B, C; scanf("%d%d%d", &A, &B, &C);
int maxv = 0;
for(int i = 1; i <= N; ++i) {
scanf("%d", v + i);
maxv = max(maxv, v[i]);
}
for(int i = v[1]; i <= maxv; ++i)
dp[1][i] = (A + B) * i;
for(int i = 2; i <= N; ++i) {
for(int j = v[i]; j <= maxv; ++j) {
dp[i][j] = inf;
for(int k = v[i-1]; k <= maxv; ++k)
dp[i][j] = min(dp[i][j], dp[i-1][k] + (k > j ? (C * (k-j) + B * j) : (A * (j - k) + B * j)));
}
}
int ans = inf;
for(int i = v[N]; i <= maxv; ++i)
ans = min(ans, dp[N][i]);
printf("%d\n", ans);
}
return 0;
}
```