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 calculation and 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 and 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.) and 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 and 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 and 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
3
100 500 10 20
120 600 8 16
220 400 7 18
0
Sample Output
778
题意:
就是说先给你一个n,代表这个系统中有n中类型的灯泡,v是这种类型灯泡的电压,每种电压的灯泡有需要一个变压器吧(我自己理解的),不管这种类型的灯泡有多少个,只需要一个这种电压变压器就可以了,第三个值是安装一个这样的灯泡多少钱,第四个值是目前这个系统中有这种灯泡多少个
我们可以用电压大的灯泡去代替电压小的灯泡,求最后这套系统的最小花费
题解:
那肯定如果某种灯泡要换那么肯定是一下子把这种灯泡一下换完(想想就知道了),那么我们对数据先初始化,对其电压从小到大排序,之后再求前i中灯泡的前缀和
每种灯泡要么换要么不换
设sum[i]为前i种灯泡的总数量(即L值之和),d[i]为灯泡1~i的最小花费,
动态转移方程就是d[i]=min(d[j]+(sum[i]-sum[j])*c[i]+k[i],d[i]);
代码:
1 //要先排序,后求和<_>
2 #include<cstdio>
3 #include<cstring>
4 #include<iostream>
5 #include<algorithm>
6 #include<vector>
7 #include<queue>
8 using namespace std;
9 typedef long long ll;
10 const int maxn=1005;
11 const int INF=0x3f3f3f3f;
12 int dp[maxn],v[maxn],ans[maxn];
13 struct shudui
14 {
15 int v,k,c,l;
16 } m[maxn];
17 bool mmp(shudui x,shudui y)
18 {
19 return x.v<y.v;
20 }
21 int main()
22 {
23 int n;
24 while(~scanf("%d",&n))
25 {
26 if(n==0) break;
27 int sum=0;
28 for(int i=1; i<=n; ++i)
29 scanf("%d%d%d%d",&m[i].v,&m[i].k,&m[i].c,&m[i].l);
30 //ans[i]=m[i].k+m[i].c*m[i].l;
31 sort(m+1,m+1+n,mmp);
32 for(int i=1;i<=n;++i)
33 v[i]=v[i-1]+m[i].l;
34 memset(dp,INF,sizeof(dp));
35 dp[0]=0;
36 for(int i=1;i<=n;++i)
37 {
38 for(int j=0;j<i;++j)
39 {
40 dp[i]=min(dp[i],dp[j]+(v[i]-v[j])*m[i].c+m[i].k);
41 }
42 }
43 printf("%d\n",dp[n]);
44 }
45 return 0;
46 }
UVA11400 Lighting System Design(DP)的更多相关文章
- UVa11400 - Lighting System Design——[动态规划]
题干略. 题意分析: 很容易理解一类灯泡要么全部换要么全不换,其实费用节省的主要原因是由于替换灯泡类型而排除了低压电压源,于是我们就可以推断出灯泡类型替换的原则: 对于两类灯泡a1和a2,a1可以被a ...
- UVA - 11400 Lighting System Design(照明系统设计)(dp)
题意:共有n种(n<=1000)种灯泡,每种灯泡用4个数值表示.电压V(V<=132000),电源费用K(K<=1000),每个灯泡的费用C(C<=10)和所需灯泡的数量L(1 ...
- UVa 11400 - Lighting System Design(线性DP)
链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- uva 11400 - Lighting System Design(动态规划 最长上升子序列问题变型)
本题难处好像是在于 能够把一些灯泡换成电压更高的灯泡以节省电源的钱 .所以也才有了对最优方案的探求 好的处理方法是依照电压从小到大排序.仅仅能让前面的换成后面的.也就满足了把一些灯泡换成电压更高的灯泡 ...
- UVa 11400 Lighting System Design【DP】
题意:给出n种灯泡,分别给出它们的电压v,电源费用k,每个灯泡的费用c,和所需灯泡的数量l,问最优方案的费用 看的紫书= = 首先是dp[i]为灯泡1到i的最小费用, dp[i]=min(dp[i], ...
- UVA - 11400 Lighting System Design (区间DP)
这个问题有两个点需要注意: 1. 对于一种灯泡,要么全换,要么全不换. 证明: 设一种灯泡单价为p1,电池价格为k1,共需要L个,若把L1个灯泡换成单价为p2,电池为k2的灯泡,产生的总花费为p1*L ...
- uva11400 Lighting System Design
题目大意: 有一个照明系统需要用到n种灯,每种灯的电压为V,电源费用K,每个灯泡费用为C,需要该灯的数量为L.注意到,电压相同的灯泡只需要共享一个对应的电源即可,还有电压低的灯泡可以被电压高的灯泡替代 ...
- 【Uva11400 Lighting System Design】动态规划
分析 先按照电压从小到大排序,做一下前缀和s[i]求i之前的电灯泡的数量. 状态:$ F_i\(表示到\) i$个灯泡的最小开销. 状态转移方程:$ F_i=F_j+(s[i]-s[j])\times ...
- 【线性结构上的动态规划】UVa 11400 - Lighting System Design
Problem F Lighting System Design Input: Standard Input Output: Standard Output You are given the tas ...
随机推荐
- 剑指offer 查找和排序的基本操作:查找排序算法大集合
重点 查找算法着重掌握:顺序查找.二分查找.哈希表查找.二叉排序树查找. 排序算法着重掌握:冒泡排序.插入排序.归并排序.快速排序. 顺序查找 算法说明 顺序查找适合于存储结构为顺序存储或链接存储的线 ...
- CAN总线采样点测试
采样点是什么? 采样点是接受节点判断信号逻辑的位置,CAN通讯属于异步通讯.需要通过不断的重新同步才能保证收发节点的采样准确. 若采样点太靠前,则因为线缆原因,DUT外发报文尚未稳定,容易发生采样错误 ...
- (十七)logging模块
logging模块是Python内置的标准模块,主要用于输出运行日志. 简单应用 import logging logging.debug('+++debug+++') logging.info('+ ...
- linux查看文件夹和磁盘内存及服务器对应的ip
多进程统计cpu 数目 n_cpu = multiprocessing.cpu_count() print(n_cpu) 查看文件夹占用磁盘空间 du -h --max-depth=1 /path 查 ...
- 【Azure Developer】解决Azure Key Vault管理Storage的示例代码在中国区Azure遇见的各种认证/授权问题 - C# Example Code
问题描述 使用Azure密钥保管库(Key Vault)来托管存储账号(Storage Account)密钥的示例中,从Github中下载的示例代码在中国区Azure运行时候会遇见各种认证和授权问题, ...
- LeetCode530. 二叉搜索树的最小绝对差
题目 又是常见的BST,要利用BST的性质,即中序遍历是有序递增序列. 法一.中序遍历 1 class Solution { 2 public: 3 vector<int>res; 4 v ...
- 20.java设计模式之解释器模式
基本需求 实现四则运算,如计算a+b-c+d的值 先输入表达式的形式,如a+b-c+d,要求表达式正确 再分别输出a,b,c,d的值 最后求出结果 传统方案 编写一个方法,接收表达式的形式,根据用户输 ...
- 分布式 ID 生成算法 — SnowFlake
一.概述 分布式 ID 生成算法的有很多种,Twitter 的 SnowFlake 就是其中经典的一种. SnowFlake 算法生成 ID 的结果是一个 64bit 大小的整数,它的结构如下图: 1 ...
- Q-Q图原理详解及Python实现
[导读]在之前的<数据挖掘概念与技术 第2章>的文章中我们介绍了Q-Q图的概念,并且通过调用现成的python函数, 画出了Q-Q图, 验证了Q-Q图的两个主要作用,1. 检验一列数据是否 ...
- 在.NET Core 中实现健康检查
.NET Core中提供了开箱即用的运行状况检查,首先,我将在.NET Core API应用程序中执行运行状况检查,接下来,我们将使用DbContext集成SQL Server或数据库的运行状况检查, ...