UVA 11400 Lighting System Design(贪心+DP)
来源:互联网 发布:关键词优化排名 编辑:程序博客网 时间:2024/06/05 08:15
Problem F
Lighting System Design
Input: Standard Input
Output: Standard Output
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.
Sample Input Output for Sample Input
3
100 500 10 20
120 600 8 16
220 400 7 18
0
778
题意:你有n个电灯设计模式要设计,每个模式需要L盏灯,每盏灯花费C,然后每个模式需要在一个电压下工作,每个电压V,电压花费K,一个电压可以提供无限大的额定电压,并且可以控制大小,换句话说,只要有一个电压V,就可以用在小于V的所有模式中,问最小需要的花费是多少。
思路:贪心,首先知道大电压可以用在小电压上,先按电压大小排个序,然后dp[i]表示前i个模式的最小花费,那么我们知道当取到i的时候,i那个电压是一定要买的,因为前面都比这个电压小,不买就没有满足的了,所以问题转化为那几个电压要买,那么状态转移方程就出来了:
dp[i] = min{dp[j] + sum};这里的sum为i到j之间模式的点灯花费(不用买电压,因为用i的就可以了)。
代码:
#include <stdio.h>#include <string.h>#include <algorithm>#define min(a,b) ((a)<(b)?(a):(b))#define INF 0x3f3f3f3fusing namespace std;const int N = 1005;int n, dp[N];struct D {int v, k, c, l;} d[N];bool cmp(D a, D b) {return a.v < b.v;}int solve(int now) {if (dp[now] != -1) return dp[now];dp[now] = INF;int sum = d[now].k;if (now == 0) return dp[now] = 0;for (int i = now; i >= 1; i--) {sum += d[now].c * d[i].l;int t = solve(i - 1);dp[now] = min(dp[now], t + sum);}return dp[now];}int main() {while (~scanf("%d", &n) && n) {memset(dp, -1, sizeof(dp));for (int i = 1; i <= n; i++)scanf("%d%d%d%d", &d[i].v, &d[i].k, &d[i].c, &d[i].l); sort(d + 1, d + n + 1, cmp);printf("%d\n", solve(n));}return 0;}
- uva 11400 - Lighting System Design(dp+贪心)
- UVA 11400 Lighting System Design 【贪心】【DP】
- UVA 11400 Lighting System Design(贪心+DP)
- uva 11400 Lighting System Design (dp)
- UVa 11400 - Lighting System Design(DP)
- UVa 11400 - Lighting System Design(DP)
- UVa 11400:Lighting System Design(DP)
- uva 11400 Lighting System Design(dp~)
- uva 11400 Lighting System Design (DP)
- Lighting System Design - UVa 11400 dp
- UVA 11400 Lighting System Design DP
- UVa 11400 Lighting System Design(DP)
- uva 11400 Lighting System Design dp
- UVA 11400 Lighting System Design DP
- UVA 11400 Lighting System Design (DP)
- UVA 11400 Lighting System Design 照明系统设计(DP)
- 11400 - Lighting System Design(DP)
- UVA 11400 Lighting System Design
- 一则C++程序设计课堂练习的记录
- SpringMvc(三)配置Mybatis
- 如何求FIRST集和FOLLOW集
- Socket编程原理
- eclipse
- UVA 11400 Lighting System Design(贪心+DP)
- ArcGIS 10.1 for Server 在windows下的安装
- 课题实验(一)
- POJ 3034 (dp) 锤子尼玛能在棋盘外面。。出题不带这么坑的
- 一种对图象进行局部放大的有效方法
- 关于Android的一些设计
- POJ 2586 Y2K Accounting Bug(贪心)
- 大学生创业指导——A Student’s Guide to Startups
- eclipse下调试图片上传,不能立即显示的问题