题文:

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的更多相关文章

  1. 【Uva 11400】Lighting System Design

    [Link]: [Description] 你要构建一个供电系统; 给你n种灯泡来构建这么一个系统; 每种灯泡有4个参数 1.灯泡的工作电压 2.灯泡的所需的电源的花费(只要买一个电源就能供这种灯泡的 ...

  2. 【线性结构上的动态规划】UVa 11400 - Lighting System Design

    Problem F Lighting System Design Input: Standard Input Output: Standard Output You are given the tas ...

  3. UVa 11400 Lighting System Design(DP 照明设计)

    意甲冠军  地方照明系统设计  总共需要n不同类型的灯泡  然后进入 每个灯电压v  相应电压电源的价格k  每一个灯泡的价格c   须要这样的灯泡的数量l   电压低的灯泡能够用电压高的灯泡替换   ...

  4. (动态规划)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 ...

  5. 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 ...

  6. uva 11400 Problem F Lighting System Design

    紫皮书题: 题意:让你设计照明系统,给你n种灯泡,每种灯泡有所需电压,电源,每个灯泡的费用,以及每个灯泡所需的数量.每种灯泡所需的电源都是不同的,其中电压大的灯泡可以替换电压小的灯泡,要求求出最小费用 ...

  7. UVA - 11400 Lighting System Design (区间DP)

    这个问题有两个点需要注意: 1. 对于一种灯泡,要么全换,要么全不换. 证明: 设一种灯泡单价为p1,电池价格为k1,共需要L个,若把L1个灯泡换成单价为p2,电池为k2的灯泡,产生的总花费为p1*L ...

  8. UVa 11400 - Lighting System Design(线性DP)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  9. UVA 11400"Lighting System Design"

    传送门 错误思路 正解 AC代码 参考资料: [1]:https://www.cnblogs.com/Kiraa/p/5510757.html 题意: 现给你一套照明系统,这套照明系统共包含 n 种类 ...

随机推荐

  1. 【Spring】 AOP Base

    1. AOP概述 2. AOP的术语: 3. AOP底层原理 4. Spring 中的AOP 4.1 概述 4.2 分类 4.3 Spring的传统AOP 针对所有方法的增强:(不带有切点的切面) 带 ...

  2. Python高效编程技巧实战 实战编程+面试典型问题 中高阶程序员过渡

    下载链接:https://www.yinxiangit.com/603.html 目录:   如果你想用python从事多个领域的开发工作,且有一些python基础, 想进一步提高python应用能力 ...

  3. Go依赖管理及Go module使用

    Go语言的依赖管理随着版本的更迭正逐渐完善起来. 依赖管理 为什么需要依赖管理 最早的时候,Go所依赖的所有的第三方库都放在GOPATH这个目录下面.这就导致了同一个库只能保存一个版本的代码.如果不同 ...

  4. 关于git远程被覆盖的问题

    有同事A和B,git远程版本为A0,两个人的本地项目已经跟远程同步.同事A先向git提交了3次,A1.A2.A3.git远程版本为A0.A1.A2.A3.同事B也向git提交了1次B1,但是同事B提交 ...

  5. Pytorch的基础数据类型

    引言 本篇介绍Pytorch的基础数据类型,判断方式以及常用向量 基础数据类型 torch.Tensor是一种包含单一数据类型元素的多维矩阵. 目前在1.2版本中有9种类型. 同python相比,py ...

  6. 05.Django基础五之django模型层(一)单表操作

    一 ORM简介 MVC或者MVC框架中包括一个重要的部分,就是ORM,它实现了数据模型与数据库的解耦,即数据模型的设计不需要依赖于特定的数据库,通过简单的配置就可以轻松更换数据库,这极大的减轻了开发人 ...

  7. redis的安装和pip连接

    一.首先说说我的环境.         操作系统:Ubuntu16.04         能联网(使用了桥接方式)   二.安装redis cd进一个文件夹. 控制台输入     weget http ...

  8. Django模板语言, 过滤器整理

    Django模板语言,过滤器整理 1. add {{ value|add:"2" }} 把add后的参数加给value: 处理时,过滤器首先会强制把两个值转换成Int类型. 如果强 ...

  9. 【系统设计】分布式唯一ID生成方案总结

    目录 分布式系统中唯一ID生成方案 1. 唯一ID简介 2. 全局ID常见生成方案 2.1 UUID生成 2.2 数据库生成 2.3 Redis生成 2.4 利用zookeeper生成 2.5 雪花算 ...

  10. 难题解决:Mycat数据库中间件+Mybatis批量插入数据并返回行记录的所有主键ID

     一.mybatis的版本必须为3.3.1及其以上 项目所依赖的mybatis的版本必须为3.3.1及其以上,低版本的不行,保证hap项目的依赖的mybatis的jar的版本必需为需要的版本: 二.在 ...