POJ 1018 Communication System(DP+离散化)
来源:互联网 发布:魅族官网商城下载软件 编辑:程序博客网 时间:2024/05/17 23:26
某公司要建立一套通信系统,该通信系统需要n种设备,而每种设备分别可以有m1、m2、m3、...、mn个厂家提供生产,而每个厂家生产的同种设备都会存在两个方面的差别:带宽bandwidths 和 价格prices。
现在每种设备都各需要1个,考虑到性价比问题,要求所挑选出来的n件设备,要使得B/P最大。
其中B为这n件设备的带宽的最小值,P为这n件设备的总价。
思路:最多就1W个带宽,可以对带宽进行离散化,然后DP,dp[i][j]表示选到第i个,带宽为j的P总和的最小值,然后状态转移即可
代码:
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;const int N = 10005;const int INF = 0x3f3f3f3f;int t, n, dp[2][N], hash[N], hn;struct Man { int m, b[105], p[105]; void read() {scanf("%d", &m);for (int i = 0; i < m; i++) { scanf("%d%d", &b[i], &p[i]); hash[hn++] = b[i];} }} man[105];int find(int x) { return lower_bound(hash, hash + hn, x) - hash;}int main() { scanf("%d", &t); while (t--) {hn = 0;scanf("%d", &n);for (int i = 1; i <= n; i++) man[i].read();sort(hash, hash + hn);hn = unique(hash, hash + hn) - hash;memset(dp[0], INF, sizeof(dp[0]));for (int j = 0; j < man[1].m; j++) dp[0][find(man[1].b[j])] = man[1].p[j];int now = 0, pre = 1;for (int i = 2; i <= n; i++) { swap(now, pre); memset(dp[now], INF, sizeof(dp[now])); for (int j = 0; j < man[i].m; j++) {for (int k = 0; k < hn; k++) { int tmp = min(find(man[i].b[j]), k); dp[now][tmp] = min(dp[now][tmp], dp[pre][k] + man[i].p[j]);} }}double ans = 0;for (int i = 0; i < hn; i++) ans = max(ans, hash[i] * 1.0 / dp[now][i]);printf("%.3f\n", ans); } return 0;}
0 0
- poj 1018 Communication System-dp+离散化
- POJ 1018 Communication System(DP+离散化)
- poj - 1018 - Communication System(dp)
- POJ 1018 Communication System(简单DP)
- poj 1018 Communication System(DP)
- poj 1018 Communication System (dp | 贪心)
- 【POJ 1018】Communication System(dp|贪心)
- POJ 1018 Communication System (DP)
- POJ 1018 Communication System dp
- POJ 1018:Communication System - DP
- POJ 1018Communication System(DP)
- poj 1018 Communication System(DP)
- poj 1018 Communication System DP思想
- poj 1018 Communication System
- POJ 1018 Communication System
- poj 1018 Communication System
- POJ 1018 Communication System
- POJ 1018 Communication System
- 电脑开不开机 且开且珍惜
- NYOJ skiing【BFS】
- Android TouchEvent事件传递机制
- Codeforces Beta Round #5 C. Longest Regular Bracket Sequence
- 传真百科:电子邮件能取代传真吗
- POJ 1018 Communication System(DP+离散化)
- OK6410A 之mmap 方式操作LED流水灯效果
- 微服务现状综述
- something about WinPE
- symlink在ln的过程中究竟占用了多少耗时
- socket程序被ctrl+c终止,再次启动报错硕地址已被使用的解决方法
- java对redis的基本操作
- Lucene4.10使用教程(八):Lucene的自定义评分(2)
- recovery输入事件及处理分析