POJ #1018 Communication System
来源:互联网 发布:sql后缀文件如何打开 编辑:程序博客网 时间:2024/06/03 16:50
简单dp题,0-1背包模型。定义d[i][j]表示考虑完前i个设备,最大bandwidth为j时的最小费用。bandwidth的范围题目中没说,但貌似不大(500以内)
#define UVa "poj-1018.cpp"//Communication Systemchar fileIn[30] = UVa, fileOut[30] = UVa;#include<cstring>#include<cstdio>#include<algorithm>using namespace std;//Global Variables. Reset upon Each Case!const int maxn = 100 + 5, maxm = 500;int kase, n;int B[maxn][maxn], P[maxn][maxn], mi[maxn], d[maxm][2];/////void update(int& targ, int src) { if(targ == -1 || targ > src) targ = src;}int main() { scanf("%d", &kase); while(kase --) { scanf("%d", &n); for(int i = 0; i < n; i ++) { scanf("%d", &mi[i]); for(int j = 0; j < mi[i]; j ++) scanf("%d%d", &B[i][j], &P[i][j]); } int t = 0; for(int i = 0; i < maxm; i ++) d[i][t] = -1; for(int u = 0; u < n; u ++) { for(int i = 0; i < maxm; i ++) d[i][t^1] = -1; for(int i = 0; i < mi[u]; i ++) { if(u == 0) update(d[B[u][i]][t^1], P[u][i]); else for(int b = 0; b < maxm; b ++) { if(d[b][t] != -1) update(d[min(b, B[u][i])][t^1], d[b][t] + P[u][i]); } } t ^= 1; } float ans = 0; for(int i = 0; i < maxm; i ++) if(d[i][t] != -1) ans = max(ans, (float)i/(float)d[i][t]); printf("%.3f\n", ans); } return 0;}
0 0
- poj 1018 Communication System
- POJ 1018 Communication System
- poj 1018 Communication System
- POJ 1018 Communication System
- POJ 1018 Communication System
- POJ 1018 Communication System
- poj 1018 Communication System
- POJ 1018 Communication System
- poj 1018 Communication System
- poj 1018 Communication System
- POJ 1018 Communication System
- poj 1018 Communication System
- poj 1018 Communication System
- poj-1018 Communication System
- POJ-1018 Communication System
- [POJ][1018]Communication System
- poj 1018Communication System
- poj 1018:Communication System
- C++习题第三章
- 网络搜索引擎简介
- DS之顺序表实现输入数据逆置
- SQL中JOIN和UNION区别、用法及示例介绍
- windows7下 64-bit 2008 R2 版本的mongodb安装
- POJ #1018 Communication System
- iOS 4种数据保存方式
- TCP/IP四层模型
- 浅谈协方差矩阵【转】
- 清除gradle依赖jar
- Structs2 HelloWorld-07 通用标签
- 读写配置文件
- 复制SQLSERVER数据库文件
- 在已有的Xcode项目中添加git管理