您的位置:首页 > 其它

uva 11400 Lighting System Design

2016-07-12 22:05 225 查看
原题:

You are given the task to design a lighting system for a huge conference hall. After doing a lot of

calculation and 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 and 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.) and 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 and 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 and 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.

Sample Input

3

100 500 10 20

120 600 8 16

220 400 7 18

0

Sample Output

778

题目大意:

让你给一个大厅安装照明系统,给你n种不同的灯,其中每种灯有如下数据,电压值,电源的价格,灯的单价,需要这个灯的数量。一个电源可以供应无数个灯,所有通过灯的电流都相同。为了节省开销,你可以把一些灯换成电压值更高的灯泡来代替(此时价格就按电压高的灯泡的价格,数量依然是被替换的那个灯泡的数量)。现在问你要安装这些数目的灯,最少要多少钱。

#include <bits/stdc++.h>
using namespace std;
const int inf=9999999;
struct light
{
int v,k,c,l;
};
light ls[1001];
int cmp(const light &l1,const light &l2)
{
return l1.v<l2.v;
}
int dp[1001];
int main()
{
ios::sync_with_stdio(false);
int n;
while(cin>>n,n)
{
for(int i=1;i<=n;i++)
cin>>ls[i].v>>ls[i].k>>ls[i].c>>ls[i].l;
sort(ls+1,ls+1+n,cmp);
memset(dp,0,sizeof(dp));
for(int i=1;i<=n;i++)
{
dp[i]=inf;
int tmp=0;
for(int j=i;j>=1;j--)
{
tmp+=ls[j].l;
dp[i]=min(dp[i],dp[j-1]+tmp*ls[i].c+ls[i].k);
}
}
cout<<dp
<<endl;
}
return 0;
}


解析:

简单的一维动态规划问题,可以参考最长递增子序列类似的那个叠箱子的问题。首先根据电压值从小到大排序,因为电压大的电源能够接电压要求下的灯泡。设置状态dp[i]表示用到第i个灯泡时花费的最少钱数。接下来找状态转移,转移过程只有两种,要么用当前灯泡的去替换后面的灯泡(因为排序过),要么不替换,如果替换,替换到第多少个。这里有个问题,比如一个灯泡需要20个,那么如果要替换这个灯泡,是全部替换,还是替换一部分才能找到最优呢?答案肯定是全部替换,因为如果当前灯泡价格1,要被替换的价格是2,那肯定是1块钱的便宜,而且还能省下一个被替换的灯泡的电源钱。

那么

dp[i]=min(dp[i],dp[j-1]+tmp*light[i].c+light[i].k)


其中light[i]是第i种灯,tmp表示计算从i往后累加的灯泡数量,加一起用来被第i个灯泡替换。所以方程的意思就是dp[i]的最优值等于前j个灯泡用第i个灯泡替换加上j-1到第一个灯泡布置照明系统时的最优值(1<=j<=i)

这里有一点要想清楚,比如现在又100个排好序的灯泡,现在要算dp[80],往前面查找状态,比如查找到了dp[50],那么酸的dp[80]就等于80到第51个灯泡的都用第80号灯泡代替再加上dp[50],那么在80到50之间是否存在有的灯泡不用第80号灯泡代替来获得最优值呢?当然存在,因为在你算到第50号之前已经枚举到了这个状态(比如第70个灯泡,此时为tmp为80到71个灯泡用第80号灯泡代替加上dp[70]的最优值),所以继续往下枚举即可。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: