题目:题目链接

思路:简单的动态规划问题,先把灯泡按照电压从小到大排序。设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. SublimeText插件eslint : 语法检测

    参考: http://www.tuicool.com/articles/faANRvj 安装之后的效果: 误用了 = ,在文件保存时就会被提示,直接顺手改掉就行了,方便的不行 步骤1:Sublime集 ...

  2. jQ中css()和addClass的区别之优先级

    笔者在实现点击表格中某行添加高亮的效果时,发现一个css()和addClassd()的冲突,具体代码如下: <style> .se { background:#FF6500; color: ...

  3. Unable to copy a file from obj\Debug to bin\Debug

    1. Exit the VS2012, and then re-open the solution. 2. Clean the solution and build.

  4. Maven 私有库和本地库的安装与配置 Sonatype Nexus + Maven

    环境:CentOS 7.0 Final.JDK8.Sonatype Nexus.Maven 虚拟机模拟IP:192.168.16.167 备注:root权限用户操作 前提:已安装 JDK8 并配置好了 ...

  5. Win10 设备补丁更新

    用户对客户端设备补丁更新保持怀疑态度,因为他们担心他们的计算机会在未经许可的情况下突然自己重启,丢失数据.虽然,您可以在更新后推迟重新启动并安排选择的时间,具体取决于更新Windows在未经您许可的情 ...

  6. java compiler没有1.8怎么办

    选择第一个点击安装,安装完成后,重启eclipse,打开java compiler 就可以选择1.8了. 成功:  扫个红包吧! Donate捐赠 如果我的文章帮助了你,可以赞赏我 1 元,让我继续写 ...

  7. Open Data for Deep Learning

    Open Data for Deep Learning Here you’ll find an organized list of interesting, high-quality datasets ...

  8. 页面dom事件防止失效的一种写法

    经常我们写事件是这样的 $('.day').on('click', function () { some(); }); 但是这样在spa模式下经常容易出现页面切换后事件失效的问题, 可以采用这样的写法 ...

  9. ABI与编译器:ABI是由内核和工具链定义和实现的

    http://book.51cto.com/art/201412/460857.htm <Linux系统编程(第2版)>第1章入门和基本概念,这一章着眼于Linux系统编程的基础概念并从程 ...

  10. 基于Mybatis的Dao层开发

    转自:https://www.cnblogs.com/rodge-run/p/6528398.html 基于Mybatis的Dao层开发 SqlSessionFactoryBuilder用于创建 Sq ...