紫皮书题:

题意:让你设计照明系统,给你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. 深入理解-HashMap

    一.HashMap概述 HashMap 在家族中位置:实现了Map接口,继承AbstractMap类.HashMap 允许key/value 都为null. 二.HashMap存储结构 HashMap ...

  2. iOS8 UITableView 分割条设置separator intent = 0 不起作用

    转自:http://blog.csdn.net/ljb_wh/article/details/40788333 ios7的时候在storyboard 设置 TableView的separator in ...

  3. pay包注释(二)

    @login_required()def to_register(request):    return render_to_response("pay/register_yeepay.ht ...

  4. Ajax 实现无刷新分页

    Ajax 实现无刷新分页

  5. Hadoop 2.x(YARN)安装配置LZO

    今天尝试在Hadoop 2.x(YARN)上安装和配置LZO,遇到了很多坑,网上的资料都是基于Hadoop 1.x的,基本没有对于Hadoop 2.x上应用LZO,我在这边记录整个安装配置过程 1. ...

  6. 基于visual Studio2013解决算法导论之023队列实现(基于数组)

     题目 基于数组的队列 解决代码及点评 #include <stdio.h> #include <stdlib.h> #include <time.h> #i ...

  7. 基于visual Studio2013解决C语言竞赛题之0505选数

     题目

  8. java socket线程通信

    关于socket线程通信的一些知识整理 一般我们需要要让两台机子进行通信,需要创建一个Server 类,一个Client类,还需要创建一个线程类 server public class Server ...

  9. Cocos Studio和Cocos2d-x版本对应关系

    链接地址:http://www.cocoachina.com/bbs/read.php?tid=182077 可以在cocos2d.cpp中查看2d-x的版本信息.   版本对应列表: Studio2 ...

  10. 用ATL写简单的ActiveX控件 .

    我正在做的项目需要用读卡器来读数据,由于系统是B/S架构的所以只能把读卡器的驱动封装成一个无界面的ActiveX控件,这样web页面中的js代码才能访问读卡器其实做起来也挺简单的,我用的环境是VS20 ...