题文:

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. Centos7 C++ 安装使用googletest单元测试

    废话不多说,直接开始吧. 环境说明 系统环境:centos7.0 g++ 版本: g++ (GCC) 4.8.5 20150623 (Red Hat 4.8.5-36) 查看方法: g++ -vers ...

  2. CCPC桂林

    在得知我们队伍前往桂林参加CPPC区域赛后,我是非常激动的,因为我们网络赛并没有得到名额,如果不是新都赠予我们名额,我们都没有出去打比赛的机会,同时,我们也不想浪费这个名额,我们也想打出成绩来,于是我 ...

  3. Java第二次作业第四题

    文本行输入学生姓名,下来框选择课程名称,文本行输入课程成绩:点击"录入"按钮,相关信息显示在文本区:点击"统计"按钮,将所有录入的成绩的平均成绩显示在另一个文本 ...

  4. 03:H.264编码原理以及视频压缩I、P、B帧

    一:前言 H264是新一代的编码标准,以高压缩高质量和支持多种网络的流媒体传输著称,在编码方面,我理解的他的理论依据是:参照一段时间内图像的统计结果表明,在相邻几幅图像画面中, 一般有差别的像素只有1 ...

  5. 会计的疑惑--BigDecimal的秘密

    为了提供公司的财务信息化,公司A上线了一套自主研发的财务系统,上班第一天,财务C姐就发现了情况不对:几项支出都对,但支出总和一直为0,赶紧向大老板报告.大老板勃然大怒,责令技术部门今天必须解决,小B负 ...

  6. 记录工作中linux相关操作

    在项目部署之后,查看日志能查看部署结果是否正确部署. 最开始查看日志我会使用cat service.log tail -f service.log vim service.log 打开日志之后 /+查 ...

  7. Tomcat部署spring boot项目

    Tomcat部署spring boot项目   需要在启动类做修改

  8. Wordpress对接小程序配置过程

    最近发现一个很棒的开源项目-WordPress版微信小程序  https://github.com/iamxjb/winxin-app-watch-life.net,详细看了下介绍非常棒,不仅支持的功 ...

  9. Linux常用命令(常用)

    一,Linux常用命令二,CentOS没有盘符,只有根目录/,可以理解为只有一个盘有一个文件夹有点特殊,画了一个房子,代表当前用户的家 1.记住一个点:区分根目录和当前用户的家cd ~ 代表回家cd ...

  10. 使用Storm进行词频统计

    词频统计 1.需求:读取指定目录的数据,并且实现单词计数功能 2.实现方案: Spout用于读取指定文件夹(目录),读取文件,将文件的每一行发射到Bolt SplitBolt用于接收Spout发射过来 ...