题目:题目链接

思路:简单的动态规划问题,先把灯泡按照电压从小到大排序。设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. 在CentOS的profile文件中配置环境变量

    # idea jdk7 settings start #JAVA_HOME=/usr/local/jdk/jdk1.7.0_79 #JRE_HOME=$JAVA_HOME/jre #PATH=$PAT ...

  2. 详解__FILE__与$_SERVER['SCRIPT_FILENAME']的区别

    废话不多说 直接上测试代码: <?php //引入的是ceshi4文件夹下的ceshi4.php; require_once './ceshi4/ceshi4.php'; 下面是ceshi4文件 ...

  3. <Android 基础(十二)> TextInputLayout,让输入框更有灵性

    介绍 Layout which wraps an {@link android.widget.EditText} (or descendant) to show a floating label wh ...

  4. JSP中的Property 'name' not found on type java.lang.String

    如果是在forEach中出现. 那么看下items里是不是没有el表达式,只是个字符串. 今天犯了好几次. 特此记录

  5. staticmethod classmethod property方法

    @staticmethod 静态方法 函数修饰符,用来修饰一个函数,类似于装饰器 class Dog(object): def __init__(self,name): self.name = nam ...

  6. Redis在Windows下安装全过程

    一.下载windows版本的Redis 去官网找了很久,发现原来在官网上可以下载的windows版本的,现在官网以及没有下载地址,只能在github上下载,官网只提供linux版本的下载 官网下载地址 ...

  7. 使用 Satis 搭建私有的 Composer 包仓库

    简述 iBrand 产品立项时是商业性质的项目,但是在搭建架构时考虑后续的通用性,因此每个模块都设计成一个 Package,作为公司内部用,因此这些包并不能提交到 packagist.org 上去. ...

  8. mysql一些常用的查询语句总结

    工作中会遇到一些比较有用的mysql查询语句,有了它,可以对mysql进行更全面的维护和管理,下面就写一下我记录的 1.按照字段ru_id查询dsc_order_goods表中ru_id出现次数由多到 ...

  9. Js arguments.callee();函数自己调用自己

    1.阶乘的时候,函数一般要用到递归算法,所以函数内部一定会调用自身 //递归,阶乘 function sum(num){ ) { ; } else{ ); //自己调用自己,递归 } } alert( ...

  10. Torch.no_grad()影响MSE损失

    相关描述 https://discuss.pytorch.org/t/torch-no-grad-affecting-outputs-loss/28595/3 今天在训练网络的时候,发现mseloss ...