Problem F
Lighting System
Design

Input: Standard
Input

Output: Standard
Output

You are given the task to design
a lighting system for a huge conference hall. After doing a lot of calculation
& sketching, you have figured out the requirements for an energy-efficient
design that can properly illuminate the entire hall. According to your design,
you need lamps of n different power
ratings. For some strange current regulation method, all the lamps need to be
fed with the same amount of current. So, each category of lamp has a
corresponding voltage rating. Now, you know the number of lamps & cost of
every single unit of lamp for each category. But the problem is, you are to buy equivalent voltage sources for all the lamp
categories. You can buy a single voltage source for each category (Each source
is capable of supplying to infinite number of lamps of its voltage rating.)
& complete the design. But the accounts section of your company soon
figures out that they might be able to reduce the total system cost by eliminating
some of the voltage sources & replacing the lamps of that category with
higher rating lamps. Certainly you can never replace a lamp by a lower rating
lamp as some portion of the hall might not be illuminated then. You are more
concerned about money-saving than energy-saving. Find the minimum possible cost
to design the system.

Input

 

Each case in the input begins
with n (1<=n<=1000), denoting the number
of categories. Each of the following n lines describes a category. A category
is described by 4 integers - V (1<=V<=132000), the voltage rating,
K (1<=K<=1000), the cost of a voltage source of this rating, C
(1<=C<=10), the cost of a lamp of this rating & L (1<=L<=100),
the number of lamps required in this category. The input terminates with a test case where n = 0. This case should not be
processed.

Output

 

For each test case, print the minimum possible cost to
design the system.

Sample Input                                                  Output
for Sample Input

3

100 500 10 20

120 600 8 16

220 400 7 18

0

读题时题意理解的不太好,看分析后才明白。给出n种电灯泡,含四种属性(V-电压,K-电源费用,C-每个灯泡费用,L-所需灯泡数量);输出最合理的照明系统设计方案,要求花费最少的钱。

自己没考虑到的是:每种电压的灯泡要么全换,要么不换。因为如果只将部分灯泡换成另一种灯泡,则需要买两种不同电压的电源。这样不划算。而且,电压高的灯泡,因电流大小相等,故功率也大,这样会节省更多的钱。

代码很简单:

 #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = ;
struct Lamp
{
int V, K, C, L;
bool operator < (const Lamp& a) const
{
return V < a.V;
}
}lamp[maxn];
int dp[maxn], sum[maxn];
int main()
{
int n;
while(~scanf("%d", &n) && n)
{
for(int i = ; i <= n; i++)
{
scanf("%d%d%d%d", &lamp[i].V, &lamp[i].K, &lamp[i].C, &lamp[i].L);
}
sort(lamp+, lamp++n);
memset(sum, , sizeof(sum));
memset(dp, , sizeof(dp));
sum[] = ;
for(int i = ; i <= n; i++)
{
sum[i] = sum[i-]+lamp[i].L;
if(i == ) dp[i] = lamp[i].C*sum[i]+lamp[i].K;
else
for(int j = ; j < i; j++)
{
if(dp[i] == ) dp[i] = dp[j]+lamp[i].C*(sum[i]-sum[j])+lamp[i].K;
else dp[i] = min(dp[j]+lamp[i].C*(sum[i]-sum[j])+lamp[i].K, dp[i]);
}
}
printf("%d\n", dp[n]);
}
return ;
}

最新文章

  1. 如何在自己的代码中实现分享视频文件或者是图片文件到微信 QQ微博 新浪微博等!!!
  2. bootstrap的一些资源
  3. socket学习笔记——select与epoll函数的使用(linux)
  4. Linux crontab定时执行任务 命令格式与详细例子
  5. vs2012远程调试
  6. 推荐两个不错的CAD二次开发(.Net)手册
  7. ssh生成密钥(供git使用)
  8. ACM比赛(第三次D)
  9. Docker创建MySQL集装箱
  10. margin传递,子元素的上下margin会传递给父级
  11. SQL Server从远程服务器导入数据
  12. sar 命令详解
  13. 20164322韩玉婷 -----EXP3 免杀原理与实践
  14. Git 概念
  15. 【JDBC】java.sql.SQLException: The server time zone value &#39;&#214;&#208;&#185;&#250;&#177;&#234;&#215;&#188;&#202;&#177;&#188;&#228;&#39; is unrecognized or represents more than one time zone.
  16. mysql 开发进阶篇系列 9 锁问题 (Innodb 行锁实现方式)
  17. Flask 键盘事件
  18. python模块_re模块
  19. fiddler 手机 https 抓包 以及一些fiddler无法解决的https问题http2、tcp、udp、websocket证书写死在app中无法抓包
  20. 《算法》第六章部分程序 part 6

热门文章

  1. Java设计模式系列之单例模式
  2. Oracle导入导出之dmp
  3. mysql数据库中查询时间
  4. AVCaptureDevice
  5. codeforces 337D 树形DP Book of Evil
  6. opencv 模板匹配与滑动窗口(单匹配) (多匹配)
  7. POS机刷卡失败的郁闷事
  8. ios开源项目(各种有用的第三方库)
  9. [PoC]某B2B网站的一个反射型XSS漏洞
  10. WCF序列化与反序列化问题