UVA - 11400 Lighting System Design
题文:
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
题解:
又是一道十分巧妙的题目,首先很容易发现对于某种灯泡,要么全换,要么不换。因为如果要换,要么是灯泡比被换的更好,要么是整体更好,所以两种情况显然全部换才更优,才能省下电源钱。其二,对于这个题目,有个非常妙的性质——要换就是换连续的一个区间。因为如果不是一个区间,而是中间有某个灯泡断开了这个区间。就说明中间的使其断开的灯泡比当前更新的灯泡更优,那么为什么不能用断开的灯泡去更新前面的呢?
所以就有了转移dp[i]=min(dp[i],dp[j]+(sum[i]-sum[j])*a[i].c+a[i].k);dp[i]表示前i个的最小花费,就是说j之前用最优方案,j之后都用i号灯泡来更新。的确,贪心加dp,十分巧妙。
代码:
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cstring>
#include<stdlib.h>
#define ll long long
#define MAXN 1010
using namespace std;
struct light{
int v,k,c,l;
}a[MAXN]; bool cmp(light x,light y){
return x.v<y.v;
} int dp[MAXN],sum[MAXN];
int main(){
while(){
int n;scanf("%d",&n);
if(!n) break;
memset(dp,,sizeof(dp));
memset(sum,,sizeof(sum));
for(int i=;i<=n;i++){
cin>>a[i].v>>a[i].k>>a[i].c>>a[i].l;
}
dp[]=;
sort(a+,a+n+,cmp);
for(int i=;i<=n;i++) sum[i]=sum[i-]+a[i].l;
for(int i=;i<=n;i++){
for(int j=i-;j>=;j--){
dp[i]=min(dp[i],dp[j]+(sum[i]-sum[j])*a[i].c+a[i].k);
}
}
printf("%d\n",dp[n]);
}
}
UVA - 11400 Lighting System Design的更多相关文章
- 【Uva 11400】Lighting System Design
[Link]: [Description] 你要构建一个供电系统; 给你n种灯泡来构建这么一个系统; 每种灯泡有4个参数 1.灯泡的工作电压 2.灯泡的所需的电源的花费(只要买一个电源就能供这种灯泡的 ...
- 【线性结构上的动态规划】UVa 11400 - Lighting System Design
Problem F Lighting System Design Input: Standard Input Output: Standard Output You are given the tas ...
- UVa 11400 Lighting System Design(DP 照明设计)
意甲冠军 地方照明系统设计 总共需要n不同类型的灯泡 然后进入 每个灯电压v 相应电压电源的价格k 每一个灯泡的价格c 须要这样的灯泡的数量l 电压低的灯泡能够用电压高的灯泡替换 ...
- (动态规划)UVA-11400:Lighting System Design
You are given the task to design a lighting system for a huge conference hall. After doing a lot of ...
- UVA11400 Lighting System Design(DP)
You are given the task to design a lighting system for a huge conference hall. After doing a lot of ...
- uva 11400 Problem F Lighting System Design
紫皮书题: 题意:让你设计照明系统,给你n种灯泡,每种灯泡有所需电压,电源,每个灯泡的费用,以及每个灯泡所需的数量.每种灯泡所需的电源都是不同的,其中电压大的灯泡可以替换电压小的灯泡,要求求出最小费用 ...
- UVA - 11400 Lighting System Design (区间DP)
这个问题有两个点需要注意: 1. 对于一种灯泡,要么全换,要么全不换. 证明: 设一种灯泡单价为p1,电池价格为k1,共需要L个,若把L1个灯泡换成单价为p2,电池为k2的灯泡,产生的总花费为p1*L ...
- UVa 11400 - Lighting System Design(线性DP)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- UVA 11400"Lighting System Design"
传送门 错误思路 正解 AC代码 参考资料: [1]:https://www.cnblogs.com/Kiraa/p/5510757.html 题意: 现给你一套照明系统,这套照明系统共包含 n 种类 ...
随机推荐
- Altera Quartus II 15.0安装
写在前面的话 开始学习之前,我们首先应该选择并安装好自己的开发工具,那么我们用什么软件来编译代码呢?梦翼师兄推荐给大家的是Altera 目前最新的Quartus II 15.0 版本,当然啦,这 ...
- 【LeetCode】BFS 总结
BFS(广度优先搜索) 常用来解决最短路径问题. 第一次便利到目的节点时,所经过的路径是最短路径. 几个要点: 只能用来求解无权图的最短路径问题 队列:用来存储每一层便利得到的节点 标记:对于遍历过的 ...
- Python高效编程技巧实战 实战编程+面试典型问题 中高阶程序员过渡
下载链接:https://www.yinxiangit.com/603.html 目录: 如果你想用python从事多个领域的开发工作,且有一些python基础, 想进一步提高python应用能力 ...
- MongoDB入门及 c# .netcore客户端MongoDB.Driver使用
MongoDB 是一个基于分布式文件存储的数据库.由 C++ 语言编写.旨在为 WEB 应用提供可扩展的高性能数据存储解决方案. MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关系 ...
- 反射,Expression Tree,IL Emit 属性操作对比
.net的反射(Reflection) 是.Net中获取运行时类型信息的一种方法,通过反射编码的方式可以获得 程序集,模块,类型,元数据等信息. 反射的优点在于微软提供的API调用简单,使用方便: 表 ...
- 计算2个GPS坐标的距离
本文转自 http://blog.csdn.net/ztp800201/article/details/44676867 Java 计算两个GPS坐标点之间的距离 1. Lat1 Lung1 表示A点 ...
- SQL DROP INDEX 语句
SQL DROP INDEX 语句 我们可以使用 DROP INDEX 命令删除表格中的索引. 用于 Microsoft SQLJet (以及 Microsoft Access) 的语法: DROP ...
- 字节输出流OutputStream
1.OutputStream是输出字节流的超类. import java.io.File; import java.io.FileOutputStream; import java.io.IOExce ...
- VMware 虚拟机三种网络模式详解
一.前言 Vmware 为我们提供了三种网络工作模式,分别是:Bridged(桥接模式).NAT(网络地址转换模式).Host-only(仅主机模式). 二.VMware 的几个常见虚拟设备 打开 V ...
- 39 (OC) 瀑布流、不规则UI
39 (OC) 瀑布流.不规则UI