题目:题目链接

思路:简单的动态规划问题,先把灯泡按照电压从小到大排序。设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. Spring文件下载

    package com.smbea.demo.controller; import java.io.BufferedInputStream; import java.io.BufferedOutput ...

  2. 高仿饿了么mock本地数据

    未使用router新版webpack.dev.conf.js配置本地数据访问:// 引入express 模块 const express = require('express') // 创建expre ...

  3. 一步步理解typedef

    1.如何用C语言实现一个函数,传递两个整形数,返回两个数的和? #include<stdio.h> int add(int a,int b) { return a+b; } void ma ...

  4. dedecms网站扩展手机网站—共用数据库真正做到电脑手机同步访问,原pc站无需改动,对原pc站无任何影响

    在如今无线互联网大潮的冲击下,越来越多的pc网站访问量下降,首当其冲的就是以pc网站为生的站长们,为了顺应无线互联网的要求,站长们很有必要为自己的pc网站扩展一套手机网站,更早的抓住手机用户的流量,使 ...

  5. Azure 3月新公布(二)

    Azure 3月新发布:HDInsight 的 Apache Hadoop 以及 ExpressRoute 超高性能网关层正式发布,SQL Database Premium RS 层发布公共预览版 A ...

  6. centos7 gearmand-1.1.15打包rpm

    wget https://github.com/gearman/gearmand/releases/download/1.1.15/gearmand-1.1.15.tar.gz -O /root/rp ...

  7. Python基础学习之语句和语法

    语句和语法 python语句中有一些基本规则和特殊字符: 井号键“#”表示之后的字符为python注释: 三引号(‘‘‘ ’’’)可以多行注释 换行“\n”是标准的行分隔符(通常一个语句一行): 反斜 ...

  8. Oracle VM VirtualBox 共享文件夹设置

    在Windows平台下,这货完全没有VMware好用,但在Linux平台就很好用. 学校机房的电脑打开虚拟机就不能插优盘,一插优盘就卡死,所以,只好用共享文件夹了. 1.在虚拟机外部新建一个文件夹 假 ...

  9. 5 - 文件I/O操作

    读写文件是最常见的IO操作.Python内置了读写文件的函数,用法和C是兼容的 写文件 #打开data.txt,创建一个实例f f = open('data.txt','w') #向文件中写内容 f. ...

  10. Android(java)学习笔记73:Intent启动Activity

    1. Intent启动Activity案例 (1)首先是main.xml和other.xml文件如下: main.xml文件: <?xml version="1.0" enc ...