//UVA11400LightingSystemDesign
#include<cstdio>
#include<cstring>
#include<algorithm>
#define M(a) memset(a, 0, sizeof(a))
using namespace std;
const int MAXN = 1e3 + 10;
struct Lamp {
int V, K, C, L;
bool operator < (const Lamp& rhs) const {
return V < rhs.V;
}
}lamp[MAXN];
int cost[MAXN], len[MAXN];
int main() {
int n;
//freopen("UVA11400out.txt", "w", stdout);
while(scanf("%d", &n) == 1 && n) {
M(cost);
for(int i = 1; i <= n; i++)
scanf("%d%d%d%d", &lamp[i].V, &lamp[i].K, &lamp[i].C, &lamp[i].L);
sort(lamp + 1, lamp + n + 1);
len[0] = 0;
for(int i = 1; i <= n; i++) len[i] = len[i - 1] + lamp[i].L;
for(int i = 1; i <= n; i++) {
cost[i] = lamp[i].K + lamp[i].C * len[i];//cost[i] 代表1到i号灯泡的最优解
for(int j = 1; j <= i; j++) {
cost[i] = min(cost[i], (len[i] - len[j]) * lamp[i].C + lamp[i].K + cost[j]);
}
}
printf("%d\n", cost[n]);
}
return 0;
}
/*
3
220 600 7 18
120 400 8 16
100 500 10 20
0
*/
/*
4
61732 269 1 83
42331 566 4 54
123135 892 4 32
61721 205 6 82
*/
UVA11400LightingSystemDesign
最新推荐文章于 2018-08-26 15:26:50 发布