题目:题目链接

思路:简单的动态规划问题,先把灯泡按照电压从小到大排序。设s[i]为前i种灯泡的总数量(即L值之和),d[i]为灯 泡1~i的最小开销,则d[i] = min{d[j] + (s[i]-s[j])*c[i] + k[i])},表示前j个先用最优方案 买,然后第j+1~i个都用第i号的电源。答案为d[n]。

AC代码:

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath> #define INF 0x3f3f3f3f #define FRER() freopen("in.txt", "r", stdin);
#define FREW() freopen("out.txt", "w", stdout); using namespace std; struct lamp {
int v, k, c, l;
bool operator < (const lamp& temp) const {
return v < temp.v;
}
}; const int maxn = + ; lamp light[maxn];
int n, dp[maxn], s[maxn]; int main()
{
// FRER();
// FREW();
while(cin >> n, n) {
for(int i = ; i <= n; ++i)
cin >> light[i].v >> light[i].k >> light[i].c >> light[i].l;
sort(light + , light + n + );
for(int i = ; i <= n; ++i)
s[i] = s[i - ] + light[i].l; for(int i = ; i <= n; ++i) {
dp[i] = s[i] * light[i].c + light[i].k;
for(int j = ; j < i; ++j)
dp[i] = min(dp[i], dp[j] + (s[i] - s[j])*light[i].c + light[i].k);
}
cout << dp[n] << endl;
}
return ;
}

Lighting System Design UVA - 11400 动态规划的更多相关文章

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

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

  2. UVa 11400 Lighting System Design(DP 照明设计)

    意甲冠军  地方照明系统设计  总共需要n不同类型的灯泡  然后进入 每个灯电压v  相应电压电源的价格k  每一个灯泡的价格c   须要这样的灯泡的数量l   电压低的灯泡能够用电压高的灯泡替换   ...

  3. UVA - 11400 Lighting System Design

    题文: You are given the task to design a lighting system for a huge conference hall. After doing a lot ...

  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 - Lighting System Design(动态规划 最长上升子序列问题变型)

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

  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

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

  9. UVa 11400 Lighting System Design【DP】

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

随机推荐

  1. Java设计模式—模板方法模式

    模板方法模式仅仅使用了Java的继承机制,但它是一个应用非常广泛的模式. 1.定义:           一个操作中的算法的框架,而将一些步骤延迟到子类中.使得子类可以不改变一个算法的结构即可重定义该 ...

  2. js 流程控制语句

    1.复合语句 2.switch语句 3.do...while语句 4.while语句 5.for语句 6.for...in语句 7.break和continue语句 9.with语句 10.if语句 ...

  3. April 19 2017 Week 16 Wednesday

    What would life be if we had no courage to attempt anything? 如果我们都没有勇气去尝试点什么,生活会变成什么样子呢? I remembere ...

  4. AD的命名规则 AD常用产品型号命名规则

    AD的命名规则 AD常用产品型号命名规则 DSP信号处理器    放大器工业用器件通信    电源管理    移动通信 视频/图像处理器等 模拟A/D    D/A 转换器 传感器    模拟器件 A ...

  5. 如何用代码填充S/4HANA销售订单行项目的数量字段

    我的任务是用代码生成S/4HANA销售订单(Sales Order)的行项目,并且填充对应的quantity(数量)值. 最开始我用了下面的代码,把quantity的值写入item字段target_q ...

  6. S/4HANA和CRM Fiori应用的搜索分页实现

    在我的博客Paging Implementation in S/4HANA for Customer Management 我介绍了S/4HANA for Customer Management里采用 ...

  7. 使用navigate导出表数据

    以下内容不算技术贴,只能算是技巧贴,要做的一个操作,从数据库A中把元素A1表,导入到数据库B中B1表,且,A1表的数据是部分导出,那么有两种方法进行导出 方法1: 选择数据表,右键,选择“转存储sql ...

  8. 使用Python命令创建jenkins的job

    目的:通过调用jenkins的命令,动态创建jenkins的job 如何使用,使用Python的脚本,更多API可以进入到官网去查看,http://jenkinsapi.readthedocs.io/ ...

  9. 【CCPC-Wannafly Winter Camp Day4 (Div1) J】跑跑跑路(爬山)

    点此看题面 大致题意: 共两轮,每轮每人有一个标签,标签相同的人必须到同一个点集合.求所有人总路程的最小值. 爬山算法 这道题貌似有三种做法:模拟退火.高斯消元以及爬山算法. 相比之下,自然是爬山算法 ...

  10. 并查集,是否成树,Poj(1308)

    思路: 对于每一条新的边的两个端点,是否是属于一颗树,要是的话,就不是一颗树.否则,就合并. 这里要注意的是,不能是森林,我这里WA了两次了.只不过在最后,查看每个节点的祖先是否是同一个就可以了. # ...