题意:共有n种(n<=1000)种灯泡,每种灯泡用4个数值表示。电压V(V<=132000),电源费用K(K<=1000),每个灯泡的费用C(C<=10)和所需灯泡的数量L(1<=L<=100)。把一些灯泡换成电压更高的另一种灯泡以节省电源的钱(不能换成电压更低的灯泡)。计算出最优方案费用。

分析:

1、每种电压的灯泡要么全换要么全不换,否则电压不同,需要买更多电源不划算。

2、把灯泡按电压从小到大排序。

3、sum[i]---前i种灯泡的总数量

4、dp[i]----灯泡1~i的最小开销

5、状态转移方程dp[i] = Min(dp[i], dp[j] + (sum[i] - sum[j]) * num[i].c + num[i].k);表示前j个先用最优方案买,第j+1~i个用第i号的电源。

#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 1000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int sum[MAXN];
int dp[MAXN];
struct Node{
int v, k, c, l;
void read(){
scanf("%d%d%d%d", &v, &k, &c, &l);
}
bool operator < (const Node& rhs)const{
return v < rhs.v;
}
}num[MAXN];
int main(){
int n;
while(scanf("%d", &n) == 1){
if(!n) return 0;
for(int i = 1; i <= n; ++i){
num[i].read();
}
sort(num + 1, num + n + 1);
sum[0] = 0;
for(int i = 1; i <= n; ++i){
sum[i] = sum[i - 1] + num[i].l;
}
dp[0] = 0;
for(int i = 1; i <= n; ++i){
dp[i] = INT_INF;
for(int j = 0; j < i; ++j){
dp[i] = Min(dp[i], dp[j] + (sum[i] - sum[j]) * num[i].c + num[i].k);
}
}
printf("%d\n", dp[n]);
}
return 0;
}

  

UVA - 11400 Lighting System Design(照明系统设计)(dp)的更多相关文章

  1. UVA 11400 Lighting System Design 照明系统设计

    首先是一个贪心,一种灯泡要么全都换,要么全都不换. 先排序,定义状态d[i]为前面i种灯泡的最小花费,状态转移就是从d[j],j<i,加上 i前面的j+1到i-1种灯泡换成i的花费. 下标排序玩 ...

  2. UVa 11400 - Lighting System Design(线性DP)

    链接: https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  3. 【线性结构上的动态规划】UVa 11400 - Lighting System Design

    Problem F Lighting System Design Input: Standard Input Output: Standard Output You are given the tas ...

  4. UVa 11400 Lighting System Design(DP 照明设计)

    意甲冠军  地方照明系统设计  总共需要n不同类型的灯泡  然后进入 每个灯电压v  相应电压电源的价格k  每一个灯泡的价格c   须要这样的灯泡的数量l   电压低的灯泡能够用电压高的灯泡替换   ...

  5. UVa 11400 Lighting System Design【DP】

    题意:给出n种灯泡,分别给出它们的电压v,电源费用k,每个灯泡的费用c,和所需灯泡的数量l,问最优方案的费用 看的紫书= = 首先是dp[i]为灯泡1到i的最小费用, dp[i]=min(dp[i], ...

  6. UVA - 11400 Lighting System Design (区间DP)

    这个问题有两个点需要注意: 1. 对于一种灯泡,要么全换,要么全不换. 证明: 设一种灯泡单价为p1,电池价格为k1,共需要L个,若把L1个灯泡换成单价为p2,电池为k2的灯泡,产生的总花费为p1*L ...

  7. UVA 11400"Lighting System Design"

    传送门 错误思路 正解 AC代码 参考资料: [1]:https://www.cnblogs.com/Kiraa/p/5510757.html 题意: 现给你一套照明系统,这套照明系统共包含 n 种类 ...

  8. UVa 11400 Lighting System Design

    题意: 一共有n种灯泡,不同种类的灯泡必须用不同种电源,但同一种灯泡可以用同一种电源.每种灯泡有四个参数: 电压值V.电源费用K.每个灯泡的费用C.所需该种灯泡的数量L 为了省钱,可以用电压高的灯泡来 ...

  9. uva 11400 - Lighting System Design(动态规划 最长上升子序列问题变型)

    本题难处好像是在于 能够把一些灯泡换成电压更高的灯泡以节省电源的钱 .所以也才有了对最优方案的探求 好的处理方法是依照电压从小到大排序.仅仅能让前面的换成后面的.也就满足了把一些灯泡换成电压更高的灯泡 ...

随机推荐

  1. .net高手:forms验证中中<forms loginUrl="" defaultUrl="">defaulturl和loginurl的区别

    .net高手:forms验证中中<forms  loginUrl="" defaultUrl="">defaulturl和loginurl的区别 d ...

  2. SQL 笔记1,left join,group by,having

    表:XS,XK,CJ left join 表1 on 表1.字段=表2.字段 group by 分组条件 order by 排序条件 asc正序(小到大),desc倒序 having 跟条件类似whe ...

  3. centos6忘记root密码

    Centos6 1.在开机时不要自动进入系统,按任意键进入GRUB引导菜单 2.按E键进入编辑模式 3.选中kernel选项继续按E键 4.在结尾处添加single关键字后按ENTER保存退出 5.之 ...

  4. 【高软作业3】:原型化系统 DevTools

    原型化系统:DevTools       密码:lcx 1. 这是一个什么样的平台? DevTools,可译为:开发者工具库.初衷是聚集各类开发工具,方便开发者获取:此外,大家可以分享自己的工具库与工 ...

  5. Opencv中常见的滤波方法

    滤波(模糊)的概念和作用: 图像滤波增强处理实质上就是运用滤波技术来增强图像的某些空间频率特征,以改善地物目标与领域或背景之间的灰度反差. 遥感系统成像过程中可能产生的”模糊”作用,常使遥感图像上某些 ...

  6. MyEclipse 8.6.1 制作绿色版

    我们先在这个目录下新建一个文件: MyEclipse 10.6.bat , 文件内容如下: start eclipse\eclipse.exe -vm jre\bin\javaw.exe 接下来只需要 ...

  7. 公用表表达式(CTE) with as 片段

    1.为什么用CTE,而不用表变量, declare @t table(CountryRegionCode nvarchar(3)) insert into @t(CountryRegionCode)  ...

  8. Ayoub's function

    思维,就是反过来想,题解太强了 #include <bits/stdc++.h> using namespace std; int main() { long long t; cin> ...

  9. POJ 3268:Silver Cow Party 求单点的来回最短路径

    Silver Cow Party Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15989   Accepted: 7303 ...

  10. 面试题之xml解析?

    题目是:用java程序将xml中的数据保存到实体对象中,如何实现? xml如下: <?xml version="1.0" encoding="UTF-8" ...