您的位置:首页 > 其它

Lighting System Design UVA - 11400

2018-01-27 16:06 465 查看
You are given the task to design a lighting system for a huge conference hall. After doing a lot of calculation & sketching, you have figured out the requirements for an energy-efficient design that can properly illuminate the entire hall. According to your
design, you need lamps of n different power ratings. For some strange current regulation method, all the lamps need to be fed with the same amount of current. So, each category of lamp has a corresponding voltage rating. Now, you know the
number of lamps & cost of every single unit of lamp for each category. But the problem is, you are to buy equivalent voltage sources for all the lamp categories. You can buy a single voltage source for each category (Each source is capable of supplying to
infinite number of lamps of its voltage rating.) & complete the design. But the accounts section of your company soon figures out that they might be able to reduce the total system cost by eliminating some of the voltage sources & replacing the lamps of that
category with higher rating lamps. Certainly you can never replace a lamp by a lower rating lamp as some portion of the hall might not be illuminated then. You are more concerned about money-saving than energy-saving. Find the minimum possible cost to design
the system.

Input

Each case in the input begins with n (1<=n<=1000), denoting the number of categories. Each of the following n lines describes a category. A category is described by 4 integers - V (1<=V<=132000), the voltage rating, K (1<=K<=1000), the cost
of a voltage source of this rating, C (1<=C<=10), the cost of a lamp of this rating & L (1<=L<=100), the number of lamps required in this category. The input terminates with a test case where n = 0. This case should not be processed.

Output

For each test case, print the minimum possible cost to design the system.

3

100 500 10 20

120 600 8 16

220 400 7 18

0

778

Sa

题意:题意就理解了好大一会儿,设计一个照明系统,有n种灯泡可选,每种灯泡有四个数值,电压,电源费用,每个灯泡费用,所需灯泡数量,可以把一些灯泡换成电压更高的另一种灯泡以节省钱,但不能换成电压更低的灯泡,解释一下样例,如果都换成第三种灯泡的话,最省钱,(20+16+18)*7 + 400 = 778.

思路:如果换掉一个灯泡可以省钱的话,那么把这种灯泡都换掉的话更省钱,由此得到一个结论,一种灯泡要么都换,要么都不换,把灯泡按照电压从小到大排序,sum【i】表示从1到i种灯泡的总数量,dp【i】位灯泡1-i的最小开销dp【i】= min(dp【j】+(sum【i】-sum【j】)*c【i】+k【i】表示前j个先用最优方案,然后j+1-i都用第i号的电源,答案为dp【n】

#include <stdio.h>
#include <algorithm>
#include <string.h>

using namespace std;

struct lamp{
int v,k,c,l;
}la[1005];
bool cmp(struct lamp a,struct lamp b){
return a.v < b.v;
}
int sum[1005];
int dp[1005];
int main(void){
int n;
while(scanf("%d",&n) && n){
for(int i = 1; i <= n; i++){
scanf("%d%d%d%d",&la[i].v,&la[i].k,&la[i].c,&la[i].l);
}
sort(la + 1,la + n + 1,cmp);
sum[0] = 0;
sum[1] = la[1].l;
for(int i = 2; i <= n; i++){
sum[i] = la[i].l + sum[i - 1];
}

memset(dp,0x3f,sizeof(dp));
dp[0] = 0;
for(int i = 1; i <= n; i++){
for(int j = 0; j <= i; j++){
//dp[i]是布置前i种灯泡的最小开销
//下面的式子表示将第j+1到第i种全部更换为第i种灯泡
dp[i] = min(dp[i],dp[j] + (sum[i] - sum[j]) * la[i].c + la[i].k);
}
}
printf("%d\n",dp
);
}

return 0;
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  dp uva