UVA11400LightingSystemDesign

//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
*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值