本文主要是介绍Lighting System Design UVA - 11400 (LIS /DP),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接:点击打开链接
You are given the task to design a lighting system for a huge conference hall. After doing a lot ofcalculation and sketching, you have figured out the requirements for an energy-efficient design thatcan properly illuminate the entire hall. According to your design, you need lamps of n different powerratings. For some strange current regulation method, all the lamps need to be fed with the sameamount of current. So, each category of lamp has a corresponding voltage rating. Now, you know thenumber of lamps and cost of every single unit of lamp for each category. But the problem is, you areto buy equivalent voltage sources for all the lamp categories. You can buy a single voltage source foreach 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 mightbe able to reduce the total system cost by eliminating some of the voltage sources and replacing thelamps of that category with higher rating lamps. Certainly you can never replace a lamp by a lowerrating lamp as some portion of the hall might not be illuminated then. You are more concerned aboutmoney-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 thefollowing n lines describes a category. A category is described by 4 integers - V (1 ≤ V ≤ 132000), thevoltage rating, K (1 ≤ K ≤ 1000), the cost of a voltage source of this rating, C (1 ≤ C ≤ 10), the costof a lamp of this rating and L (1 ≤ L ≤ 100), the number of lamps required in this category. The inputterminates 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
题目大意:
紫书p275
(今天做的都是LIS类型的,特点就是记录前i的状态,从0-i中寻找j,更新从j+1~i的数值+前j的最优值)
设计一个照明系统,一共有n种灯泡(n<=1000)可供选择,不同种类的灯泡有不同的电源,但同一种灯泡可以共用一个电源,每种灯泡用四个数表示:电压值,电源费用,每个灯泡的费用和所有需要灯泡的数量L.由于电压越高效率越高,那么尽量选电压高的,为了节省电源费用,求出最优方案的费用。
ps:这题意真的是挺让人头疼的,上面是紫书上的翻译,我还是在根据自己的理解翻译一下吧:意思是一共有n种灯泡,用哪一种都行,每种可以用一个电源,因为每种的数量不唯一,但这些同种的都可以用一个电源,关键就是这里使得最优的。既然这样那么,对于第i种灯泡,要么全都用,要么都不用,(其实这里指的是换掉以前的灯泡的时候的用法,比如:在第j种到第i种的灯泡中,都换成第k种灯泡,这k中会用同一个电源,而如果只换了一部分,那么相对都换点而言的话,多加了另一种灯泡的电源费用(好拗口))。因为电压高的效率高,所以先以电压从大到小排序,在优化时,进行从低电压往高电压寻找,如果对于相对高的电压更优化,那么就更新。
记dp[i]表示前i种所得出的最小开销,然后从0-i寻找j,让从j~i换为第i种灯泡时的费用,比较是不是更优化,如果是就跟新。则转移方程为:dp[i]=min{dp[j]+(s[i]-s[j])*c[i]+k[i]}其中dp[j]表示前j中的最小花费,s[i]表示前i种灯泡的数量。
记得在记录s[i]时是排序好的
#include <iostream>
#include <bits/stdc++.h>
#define INF 0x3f3f3f3fusing namespace std;struct node
{int v;int k;int c;int l;
} q[1111];
int s[1111];
int dp[1111];
bool cmp(node x,node y)
{return x.v<y.v;
}
int main()
{int n;while(scanf("%d",&n),n){s[0]=0;for(int i=1; i<=n; i++){scanf("%d%d%d%d",&q[i].v,&q[i].k,&q[i].c,&q[i].l);}sort(q+1,q+1+n,cmp);for(int i=1;i<=n;i++){s[i]=s[i-1]+q[i].l;}dp[0]=0;for(int i=1; i<=n; i++){for(int j=0; j<=i; j++){if(j==0)dp[i]=s[i]*q[i].c+q[i].k;elsedp[i]=min(dp[i],dp[j]+(s[i]-s[j])*q[i].c+q[i].k);}}printf("%d\n",dp[n]);}return 0;
}
这篇关于Lighting System Design UVA - 11400 (LIS /DP)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!