UVA11400-Lighting System Design(动态规划基础)
Accept: 654 Submit: 4654
Time Limit: 3000 mSec
Problem Description
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
Sample Input
100 500 10 20
120 600 8 16
220 400 7 18
0
Sample Output
778
题解:dp[i]表示前i种灯的最小花费并且i这种灯的电源被使用了,那么状态转移就很简单了,就是前j种(j<i)灯的最小花费,加上从j+1到i种灯的最小花费。
#include <bits/stdc++.h> using namespace std; const int maxn = + ;
const int INF = 0x3f3f3f3f; int n;
int sum[maxn], dp[maxn]; struct Lamp {
int v, k, c, l;
bool operator < (const Lamp &a)const {
return v < a.v;
}
}lamp[maxn]; int main()
{
//freopen("input.txt", "r", stdin);
while (~scanf("%d", &n) && n) {
for (int i = ; i <= n; i++) {
scanf("%d%d%d%d", &lamp[i].v, &lamp[i].k, &lamp[i].c, &lamp[i].l);
}
sort(lamp + , lamp + n + ); memset(dp, INF, sizeof(dp));
sum[] = dp[] = ;
for (int i = ; i <= n; i++) {
sum[i] = sum[i - ] + lamp[i].l;
}
for (int i = ; i <= n; i++) {
for (int j = ; j < i; j++) {
dp[i] = min(dp[i], dp[j] + (sum[i] - sum[j])*lamp[i].c + lamp[i].k);
}
} printf("%d\n", dp[n]);
}
return ;
}
UVA11400-Lighting System Design(动态规划基础)的更多相关文章
- UVa11400 - Lighting System Design——[动态规划]
题干略. 题意分析: 很容易理解一类灯泡要么全部换要么全不换,其实费用节省的主要原因是由于替换灯泡类型而排除了低压电压源,于是我们就可以推断出灯泡类型替换的原则: 对于两类灯泡a1和a2,a1可以被a ...
- 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 ...
- 【Uva11400 Lighting System Design】动态规划
分析 先按照电压从小到大排序,做一下前缀和s[i]求i之前的电灯泡的数量. 状态:$ F_i\(表示到\) i$个灯泡的最小开销. 状态转移方程:$ F_i=F_j+(s[i]-s[j])\times ...
- uva11400 Lighting System Design
题目大意: 有一个照明系统需要用到n种灯,每种灯的电压为V,电源费用K,每个灯泡费用为C,需要该灯的数量为L.注意到,电压相同的灯泡只需要共享一个对应的电源即可,还有电压低的灯泡可以被电压高的灯泡替代 ...
- 【线性结构上的动态规划】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
You are given the task to design a lighting system for a huge conference hall. After doing a lot of ...
- 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 ...
- Lighting System Design UVA - 11400 动态规划
题目:题目链接 思路:简单的动态规划问题,先把灯泡按照电压从小到大排序.设s[i]为前i种灯泡的总数量(即L值之和),d[i]为灯 泡1-i的最小开销,则d[i] = min{d[j] + (s[i] ...
- 【神仙DP】【UVa11400】Lighting System Design
传送门 Description Translation 题目大意:有一个照明系统需要用到n种灯,每种灯的电压为V,电源费用K,每个灯泡费用为C,需要该灯的数量为L.注意到,电压相同的灯泡只需要共享一个 ...
随机推荐
- python文件夹copy器(多进程版)
本节的练习的要求如下: 输入要拷贝文件夹的文件名称 读取该文件夹下的所有文件 启动5个进程来拷贝文件夹,将拷贝成功的文件名称放入队列中 主进程中显示文件拷贝的进度 代码如下: import multi ...
- Android Studio 学习(四) 数据库
文件存储 写数据 String data = "Data ti save"; FileOutputStream out =null; BufferedWriter writer = ...
- git参考, 小结
git官网: https://git-scm.com 菜鸟教程: http://www.runoob.com/git/git-tutorial.html 廖雪峰: https://www.liaoxu ...
- 07-HTML-内嵌标签
<html> <head> <title>内嵌标签学习</title> <meta charset="utf-8"/> ...
- 【读书笔记】iOS-使用钥匙串保护数据
一,将应用从设备上删除时,并不会删除其钥匙串项,这使得调试工作困难得多.模拟器有一个Reset Contents and Settings选项,可用于将钥匙串项移除.因此,强烈建议在模拟器上确定Key ...
- Redis 保护模式
默认 redis 启用了保护模式,即如果是远程链接不能进行 CRUD 等操作,如果进行该操作报错如下 (error) DENIED Redis is running in protected mode ...
- SOD框架--系统概要
SOD框架(源PDF.NETE框架)系统概要介绍 --核心三大功能(S,O,D): SQL-MAP XML SQL config and Map DAL SQL Map Entity ORM OQL( ...
- Python 基于Python从mysql表读取千万数据实践
基于Python 从mysql表读取千万数据实践 by:授客 QQ:1033553122 场景: 有以下两个表,两者都有一个表字段,名为waybill_no,我们需要从tl_waybill_b ...
- Flutter 布局(一)- Container详解
本文主要介绍Flutter中非常常见的Container,列举了一些实际例子介绍如何使用. 1. 简介 A convenience widget that combines common painti ...
- eclipse配置环境变量 (特别是输入javac无显示问题)
下载JDK:http://www.oracle.com/technetwork/java/javase/downloads/index.html 最近win10恢复了一下系统,重新给eclipse配一 ...