参考 http://www.cnblogs.com/Kiraa/p/5510757.html

http://www.cnblogs.com/zhaopAC/p/5159950.html

根据题目说明中的这句话

reduce the total system cost by eliminating some of the voltage sources and replacing the
lamps of that category with higher rating lamps.

可以判断某种电压的灯泡如果要换就全换,否则就不会eliminate某种电压。

这条题目的难点在于最优解符合一定的模式。

设d[i]为子问题灯泡1...i的最小开销,当前考虑灯泡种类i,d[i-1]已经是最优解。

编号1...(i-1)代表每种灯泡,按照电压从低到高排序,在最优解中,可能某个编号代表的灯泡已经被替换,但数量不变。

设每种灯泡的参数分别存放在V[],K[],C[],L[]这些数组中。

设 1<=j<=(i-1),j这种灯泡可以被替换成i这种灯泡,那么需要满足以下这些条件

1) V[j] < V[i]

2) K[j] + C[j]*L[j] < C[i]*L[j]

如果在编号 (j+1)...(i-1)这些种类的灯泡中有个编号x != j

因为1...(i-1)这些灯泡已经构成的最优解,j没有被x替换,那么需要满足以下这些条件

3) V[j] < V[x]

4) K[j] + C[j]*L[j] >= C[x]*L[j]

根据公式 2) 和 4)可知

C[x] <= C[i]

所以 K[x] + C[x]*L[x] < C[i]*L[x]

所以x这种灯泡也可以被替换成i

替换的模式是,如果某种灯泡可以被替换成i,那这种灯泡右边的灯泡都可以被替换成i

设s[i]为前i种灯泡的总数量,

d[i] = min{d[j] + (s[i]-s[j])*C[i] + K[i]} // 0 <= j <= (i-1)

1...j不替换,费用是d[j],(j+1)到(i-1)被替换成i,费用是(s[i]-s[j])*C[i] + K[i]

j = 0时,d[0] = 0,s[0] = 0,d[i] = s[i] * C[i] + K[i],相当于全部替换成i

#define _CRT_SECURE_NO_WARNINGS 

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <numeric> using namespace std; struct Lamp {
int V; // 1 <= V <= 132000, voltage rating
int K; // 1 <= K <= 1000, cost of voltage source of this rating
int C; // 1 <= C <= 10, cost of a lamp of this rating
int L; // 1 <= L <= 100, number of lamps required
}; int n; // 1 <= n <= 1000
const int maxn = ;
Lamp a[maxn + ];
int s[maxn + ];
int d[maxn + ]; bool comp(const Lamp &a, const Lamp &b)
{
return a.V < b.V;
} int main()
{ while (scanf("%d", &n) && n) {
for (int i = ; i <= n; i++){
scanf("%d%d%d%d", &a[i].V, &a[i].K, &a[i].C, &a[i].L);
} sort(a + , a + n + , comp); // sort based on voltage s[] = ; // s[i] = sum of numbers of 1..i types of lamps
for (int i = ; i <= n; i++) {
s[i] = s[i - ] + a[i].L;
} d[] = ; // d[i] = minium cost with 1..i types of lamps
for (int i = ; i <= n; i++){
d[i] = a[i].K + a[i].C * s[i]; // replace all lamps with type i
for (int j = ; j < i; j++) {
d[i] = min(d[i], d[j] + (s[i] - s[j])*a[i].C + a[i].K); // replace j+1...i with type i
}
} printf("%d\n", d[n]);
} return ;
}

9-6 UVa 11400的更多相关文章

  1. Uva 11400,照明系统设计

    题目链接:https://uva.onlinejudge.org/external/114/11400.pdf 题意:有一个照明系统需要用到n种灯,每种灯的电压为V,电源费用K,每个灯泡费用为C,需要 ...

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

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

  3. UVa 11400 Lighting System Design

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

  4. UVa 11400 Lighting System Design【DP】

    题意:给出n种灯泡,分别给出它们的电压v,电源费用k,每个灯泡的费用c,和所需灯泡的数量l,问最优方案的费用 看的紫书= = 首先是dp[i]为灯泡1到i的最小费用, dp[i]=min(dp[i], ...

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

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

  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 照明系统

    有一个照明系统需要用到n种灯,每种灯的电压为V,电源费用K,每个灯泡费用为C,需要该灯的数量为L.注意到,电压相同的灯泡只需要共享一个对应的电源即可,还有电压低的灯泡可以被电压高的灯泡替代.为了节约成 ...

  9. UVa 11400 照明系统设计

    https://vjudge.net/problem/UVA-11400 题意: 有一个照明系统需要用到n种灯,每种灯的电压为V,电源费用K,每个灯泡费用为C,需要该灯的数量为L.注意到,电压相同的灯 ...

  10. uva 11400 - Lighting System Design(动态规划 最长上升子序列问题变型)

    本题难处好像是在于 能够把一些灯泡换成电压更高的灯泡以节省电源的钱 .所以也才有了对最优方案的探求 好的处理方法是依照电压从小到大排序.仅仅能让前面的换成后面的.也就满足了把一些灯泡换成电压更高的灯泡 ...

随机推荐

  1. 开始使用Apache弗林克和Mapr Streams

    Introduction MapR Ecosystem Package 2.0 (MEP) is coming with some new features related to MapR Strea ...

  2. 解决WSL上运行plantUML中文乱码问题

    生成UML图命令: java -jar plantuml.jar -charset UTF-8 my.txt 1. 保证my.txt 使用uft-8编码 2. wsl中安装中文字体: 如: sudo ...

  3. leetcode 1-20 easy

    1.Two Sum Given an array of integers, return indices of the two numbers such that they add up to a s ...

  4. Direct2D 第6篇 绘制多种风格的线条

    原文:Direct2D 第6篇 绘制多种风格的线条 上图是使用Direct2D绘制的线条,Direct2D在效率上比GDI/GDI+要快几倍,GDI/GDI+绘图是出了名的"慢", ...

  5. Mathematica 和 MATLAB、Maple 并称为三大数学软件

    Mathematica是一款科学计算软件,很好地结合了数值和符号计算引擎.图形系统.编程语言.文本系统.和与其他应用程序的高级连接.很多功能在相应领域内处于世界领先地位,它也是使用最广泛的数学软件之一 ...

  6. 数据挖掘python,java

    互联网公司zamplus诚聘以下职位: (1)数据挖掘工程师 (Location:上海.北京) 岗位职责: 1. 研究基于sponsored search, content match和behavio ...

  7. github中markdown语言的使用规则

    开始使用github就接触了markdown,确实如它的宗旨所言"易读易写",语法简洁明了,功能比纯文本更强,是一种非常适用于网络的书写语言.并且一大优点是兼容HTML,只要不在m ...

  8. 【风马一族_php】NO4_php基础知识

    原文来自:http://www.cnblogs.com/sows/p/6017018.html(博客园的)风马一族 侵犯版本,后果自负 回顾 运算符:算术运算符.逻辑运算符.比较运算符.位运算符.赋值 ...

  9. Linux配置redis开机启动(CentOS 7)

    https://blog.csdn.net/qq_31803503/article/details/79246205 本次配置linux版本是CentOS 7 首先将  redis-3.2.3/uti ...

  10. Python发送邮件1(带附件的)

    普通的发邮件(不使用类)