紫皮书题:

题意:让你设计照明系统,给你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. AWVS介绍(转)

    使用AWVS对域名进行全局分析,深入探索: 首先,介绍一下AWVS这个工具. Acunetix Web Vulnerability Scanner(简称AWVS)是一款知名的网络漏洞扫描工具,它通过网 ...

  2. 多模块Maven项目怎样使用javadoc插件生成文档

    需求 近期要对一个项目结构例如以下的Maven项目生成JavaDoc文档. Project                         |-- pom.xml                   ...

  3. linux 内核代码精简

    #为了提高性能,文件系统一般都是以 relatime形式挂载进来的,见:/etc/fstab #更新一下mtime,这样,编译过程中用到的文件的atime都会被更新 find . -exec touc ...

  4. 前端上传组件 - Plupload

    http://www.cnblogs.com/KTblog/p/4740852.html 效果: 起始界面. ------------- 可以上上传单个文件. ------------- 可以上传多个 ...

  5. C中的链接属性及作用域

    如果相同的标识符出现在几个不同的源文件中时,它们是表示相同的实体,还是不同的实体.标识符的链接属性决定如何处理在不同文件中出现的标识符.标识符的作用域与它的链接属性有关. 链接属性一般有三种:exte ...

  6. DHTMLX系列组件的学习笔记

    <link rel="stylesheet" type="text/css" href="codebase/skins/dhtmlxeditor ...

  7. JavaScript下全选反选的Demo程序里实现checkmeonly函数 DOM

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. net异步编程之await

    net异步编程之await 初探asp.net异步编程之await   终于毕业了,也顺利进入一家期望的旅游互联网公司.27号入职.放肆了一个多月没写代码,好方啊. 另外一下观点均主要针对于await ...

  9. C/C++取出变量的每一位的值(第一次知道还有QBitArray)

    前写程序最多也只是字节级别操作,用char和memcpy进行一系列内存操作.此次一个sdk,其状态值直接是每位一个标示,所以需要取出每位进行操作.当然CPP也有丰富的位运算操作,但是虽然也学过,知道意 ...

  10. [poj 1265]Area[Pick定理][三角剖分]

    题意: 给出机器人移动的向量, 计算包围区域的内部整点, 边上整点, 面积. 思路: 面积是用三角剖分, 边上整点与GCD有关, 内部整点套用Pick定理. S = I + E / 2 - 1 I 为 ...