uva11400
来源:互联网 发布:5号电池多少毫安 知乎 编辑:程序博客网 时间:2024/05/16 19:30
题目中要求为了省钱,可以 把一些灯泡换成电压更高的另一些灯泡来节省电源的钱。于是,就有了按照电压排序后的动态规划
首先s[i]为前i种灯泡的数量之和,既L之和。然后定义 d[i]为1~i的最小花销,
那么d[i] = min(d[i], d[j] + (s[i]-s[j]) * c[i] + k[i]);(j < i).表示前j个用最佳方案,然后j+1 ~ i个全部都换成了电压更高的i号电源,因为电源相同的话就减少了点源的开销,答案为d[n];
/*********************************************** * Author: fisty * Created Time: 2015/2/12 17:17:46 * File Name : uva11400.cpp *********************************************** */#include <iostream>#include <cstring>#include <deque>#include <cmath>#include <queue>#include <stack>#include <list>#include <map>#include <set>#include <string>#include <vector>#include <cstdio>#include <bitset>#include <algorithm>using namespace std;#define Debug(x) cout << #x << " " << x <<endl#define Memset(x, a) memset(x, a, sizeof(x))const int INF = 0x3f3f3f3f;typedef long long LL;typedef pair<int, int> P;#define FOR(i, a, b) for(int i = a;i < b; i++)#define MAX_N 1100int n;struct node{ int v; int k; int c; int l;}lamp[MAX_N];bool cmp(node a, node b){ return a.v < b.v;}int dp[MAX_N];int s[MAX_N];int main() { //freopen("in.cpp", "r", stdin); //cin.tie(0); //ios::sync_with_stdio(false); while(cin >> n){ Memset(lamp, 0); Memset(s, 0); if(!n) break; FOR(i, 1, n+1){ cin >> lamp[i].v >> lamp[i].k >> lamp[i].c >> lamp[i].l; } Memset(dp, 0); sort(lamp + 1, lamp + 1 + n, cmp); for(int i = 1;i <= n; i++){ s[i] = s[i-1] + lamp[i].l; } for(int i = 1;i <= n; i++){ for(int j = 0;j < i; j++){ if(j == 0){ dp[i] = s[i]*lamp[i].c + lamp[i].k; }else{ dp[i] = min(dp[i],dp[j] + (s[i]-s[j])*lamp[i].c + lamp[i].k); } } } cout << dp[n] << endl; } return 0;}
2 0
- uva11400
- UVa11400
- uva11400 Lighting System Design
- UVa11400 Lighting System Design
- UVA11400 - Lighting System Design
- uva11400 lighting system design
- uva11400 动态规划
- 动态规划uva11400
- UVA11400 简单DP
- [UVa11400]照明系统设计
- UVa11400 Lighting System Design
- UVA11400照明系统设计
- UVA11400 分析推理+dp
- uva11400--Lighting System Design DP
- 解题报告 之 UVA11400 Lighting System Design
- 例题9-6 UVa11400 Lighting System Design(DP)
- 例题9-7 UVa11400 Partitioning by Palindromes(DP+回文串)
- float型变量format转换中精确度设置时将int常数赋值给float型变量报错
- poj 2251 逃出牢笼,简单的bfs
- ZOJ 2850 Beautidul Meadow(水题)
- Oracle中使用MD5加密
- C++11 中STL库中新增内容
- uva11400
- DIV为空时仍然保持占位
- Windows 10技术预览版系统激活
- Java练习题-输入一个字符串,输出该字符串中字符的所有组合
- 玩转DWZ (一)---项目中怎么使用dwz
- JAVA算法题目:给一个不多于5位的正整数,要求:一、求它是几位数,二、逆序打印出各位数字。
- Oracle merge 语句
- 软件架构经典书籍
- uva 10085 The most distant state(BFS + HASH)