题文:

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. python每日经典算法题5(基础题)+1(中难题)

    现在,越来越多的公司面试以及考验面试对算法要求都提高了一个层次,从现在,我讲每日抽出时间进行5+1算法题讲解,5是指基础题,1是指1道中等偏难.希望能够让大家熟练掌握python的语法结构已经一些高级 ...

  2. jQuery的大小拖动

    原来一直没有拖动放大的效果,居然只是没有jquery-ui.css的样式文件,虽然这是一个很小的部分,但是防微杜渐.程序本来就是个不容有小错误的存在. 如果没有样式文件,那么可以收缩的三角形就不会出现 ...

  3. Go第三方日志库logrus

    日志是程序中必不可少的一个环节,由于Go语言内置的日志库功能比较简洁,我们在实际开发中通常会选择使用第三方的日志库来进行开发.本文介绍了logrus这个日志库的基本使用. logrus介绍 Logru ...

  4. ReentrantReadWriteLock总结

    ReentrantReadWriteLock的流程的一些特性: // ReentrantReadWriteLock.WriteLock.lock()特性: • 已持有读锁的线程不能再持有写锁: • 已 ...

  5. .NET Core 3.0之深入源码理解Host(二)

      写在前面 停了近一个月的技术博客,随着正式脱离996的魔窟,接下来也正式恢复了.本文从源码角度进一步讨论.NET Core 3.0 中关于Host扩展的一些技术点,主要讨论Long Run Pro ...

  6. Windows10 系统更新之后找不到输入法

    是因为 , 系统更新之后 , 系统自带的输入法没有更新好 , 过个一两天,系统会自动修复. 简单解决办法是 , Ctrl+Alt+delete 打开任务管理器, 在进程中,按CPU大小排序,找到输入法 ...

  7. javascript实现二叉搜索树

    在使用javascript实现基本的数据结构中,练习了好几周,对基本的数据结构如 栈.队列.链表.集合.哈希表.树.图等内容进行了总结并且写了笔记和代码. 在 github中可以看到  点击查看,可以 ...

  8. windows任务计划定时备份sqlserver数据库

    使用windows的任务计划新建一个sqlserver数据库的定时备份任务 一.      (我是以sqlserver2008r2数据库版本测试的)在G盘下新建文集夹Database_backup,首 ...

  9. Bean 装配,从 Spring 到 Spring Boot

    目录  从SSM的集成谈到Bean的装配  Bean的装配 由XML到Java Config 自动扫描 Bean的注入 SSM集成的Java版 Spring Boot Magic Auto Confi ...

  10. 编写优雅代码,从挖掉恶心的if/else 开始

    背景 长话短说, 作为开发人员经常需要根据条件灵活查询数据库,不管你是用rawsql 还是EFCore, 以下类似伪代码大家都可能遇到: /// <summary> /// 灵活查询 能耗 ...