题目:题目链接

思路:简单的动态规划问题,先把灯泡按照电压从小到大排序。设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. svg用作背景图

    svg用做背景图的几种方式 1. 直接使用 background: url('data:image/svg+xml;charset=utf-8,<svg width="10" ...

  2. 设置Tomcat的字符编码

    在 server.xml 中的 Connector 标签在加入 URIEncoding="UTF-8" 属性. <Connector port="8080" ...

  3. extjs 6

    因为最近公司要写一个项目前台所以开始学习extjs前端框架,希望一起共勉. 那么我们的教程就从 Hello World 讲起. helloWorld.js   Ext.onReady(function ...

  4. Azure 4月新公布

    Azure 4 月新发布:Linux 上的 Azure Service Fabric 公共预览版正式发布:Azure 物联网套件新增设备管理功能:计量名称变更 Linux 上的 Azure Servi ...

  5. Azure 7 月新公布

    Azure 7月新发布:Cosmos DB,事件中心捕捉功能,Hybrid Connections,流量管理器快速故障转移功能. 您现有的 DocumentDB 资源现已作为 Azure 门户上 Az ...

  6. chrome浏览器设置12px以下字体大小

    内容很简单 在 body 上添加一个 css 属性即可. .body { -webkit-text-size-adjust: none; } 结束,晚安!

  7. mongdb增加字段和删除字段

    增加字段 db.xxx.update({},{"$set":{"column1":1,"column2":0}},false,true); ...

  8. python 字符串部分总结

    字符串 对于单个字符的编码,Python提供了ord()函数获取字符的整数表示,chr()函数把编码转换为对应的字符 >>> ord('A') 65 >>> ord ...

  9. sql server 拆分字符串,拆分两次(:和;)

    declare @DisciplineID int declare @paramStringVal nvarchar() declare @NPNT nvarchar() declare @Disci ...

  10. EF写INNER JOIN 链接

    面对多表的查询,一般都是多表连接后下面再写条件,但是有一种写法可以提升一下EF生成的语句的效率 首先先去查询每一个表,把每一个表对应的条件附加上去,注意:过滤数据最多的条件放在首先位置 var lt ...