紫皮书题:

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

题解:每种电压灯泡要么全换,要么全不换,因为只换部分还要加额外的电源费用,并且换了部分之后费用更少,不如全换

  先把灯泡按照电压从小到大排序,这样进行dp时,后面的电压大的如果比电压小的更优的话就可以替换了

  设dp[j]为前j个最优了,则dp[i] = min{dp[i],dp[j] + (s[i]-s[j]) * c[i] + k[i]} dp[i]在使用前要初始化为最大

  s为前i种灯泡的总数量,s[i] - s[j]表示从 i 到 j 替换为 i 则费用为 (s[i] - s[j]) * c[i] + k[i] 还要加上前 j 个灯泡的费用 dp[j];

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
const int INF = 0xfffffff;
const double ESP = 10e-;
const double Pi = atan() * ;
const int MOD = ;
const int MAXN = + ;
typedef long long LL;
using namespace std; struct Light{
int v,k,c,l;
bool operator < (Light a)const{
return v < a.v;
}
}; Light light[MAXN];
LL dp[MAXN];
LL s[MAXN]; int main(){
// freopen("input.txt","r",stdin);
int n;
while(~scanf("%d",&n) && n){
for(int i = ;i <= n;i++){
scanf("%d%d%d%d",&light[i].v,&light[i].k,&light[i].c,&light[i].l);
}
sort(light+,light+n+);
s[] = ;
for(int i = ;i <= n;i++){
s[i] = light[i].l + s[i-];
}
dp[] = ;
for(int i = ;i <= n;i++){
dp[i] = INF;
for(int j = ;j <= i;j++){
dp[i] = min(dp[i],dp[j]+(s[i] - s[j]) * light[i].c + light[i].k);
}
}
printf("%lld\n",dp[n]);
}
return ;
}

uva 11400 Problem F Lighting System Design的更多相关文章

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

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

  2. Codeforces Gym 100286F Problem F. Fibonacci System 数位DP

    Problem F. Fibonacci SystemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...

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

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

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

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

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

  8. 【Uva 11400】Lighting System Design

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

  9. UVa 11400 Lighting System Design

    题意: 一共有n种灯泡,不同种类的灯泡必须用不同种电源,但同一种灯泡可以用同一种电源.每种灯泡有四个参数: 电压值V.电源费用K.每个灯泡的费用C.所需该种灯泡的数量L 为了省钱,可以用电压高的灯泡来 ...

随机推荐

  1. javaScript 网页特效 输出语句

    大家好,我是小强老师,今天主要讲解 三个最为常用的输出语句.  alert() 弹出警示框 window.alert(‘继续学习’);  完整的写法 效果如下: 因为alert 属于window 对象 ...

  2. java计算两个日期相差多少天

    java计算两个日期相差多少天 public class DateUtil{ public static int betweenDays(Date startDate, Date endDate ) ...

  3. 基于visual Studio2013解决算法导论之021单向循环链表

     题目 单向循环链表的操作 解决代码及点评 #include <stdio.h> #include <stdlib.h> #include <time.h> ...

  4. 一天一个类,一点也不累之TreeSet

    一天一个类,一点也不累. 现在要说的是---TreeSet public class TreeSet<E> extends AbstractSet<E> implements ...

  5. Ubuntu一些配置和技巧

    安装google-chrome wget https://dl.google.com/linux/direct/google-chrome-stable_current_i386.deb sudo d ...

  6. 一步一步重写 CodeIgniter 框架 (3) —— 用面向对象重构代码

    前面两篇文章为了重点突出 CodeIgniter 框架的原理,程序的结构很乱,有很多全局变量,在这一课中我们采用面向对象的方法对原先代码进行重构. 到目前为止,程序主要完成的就是 URL 分析,并根据 ...

  7. Blog 转移

    Blog 转移至 http://blog.rapcoder.com CSDN :  http://blog.csdn.net/a542551042 欢迎一起交流 学习 ,谢谢!!!

  8. bash on windows

    bash on windows 今年微软Build 2016大会最让开发人员兴奋的消息之一,就是在Windows上可以原生运行Linux bash,对开发人员来说,这是一个喜闻乐见的消息. 1 安装 ...

  9. VC动态轨迹画线

    分类: 2.4 线程/图形学2010-04-30 22:14 1878人阅读 评论(0) 收藏 举报 文档null 这是一个绘制直线的简单绘图程序,能过实现动态轨迹画线,在拖动时产生临时线来表示可能画 ...

  10. C语言指针和数组知识总结(下)

    一.数组指针: 数组指针就是一个指针,只不过它指向的是一个数组.可以通过如下方式来定义 typedef int Array[5]; //数组类型 Array* m;      //数组定义 还有一种更 ...