poj 1018 Communication System(DP)
来源:互联网 发布:昆明行知中学怎么样 编辑:程序博客网 时间:2024/05/02 02:40
题意:
一个通信系统需要n个设备,每个设备有两个属性带宽B和价格P,第i个设备有mi个厂家生产,从中挑选n个设备,问n个设备中最小的带宽/总价格(B/P)的最大值是多少;
思路:
dp[i][j]表示前i个设备中带宽为j的最小费用(相同带宽费用越小,B/P越大)
dp[i][j]=min(dp[i][j],dp[i-1][j]+p);
#include<iostream>#include<cstdio>#include<cstring>#include<math.h>#include<algorithm>using namespace std;const int INF=0x3f3f3f3f;const int maxn=1005;int t,n,m;int dp[105][maxn];//dp[i][j]表示前i个设备带宽为j的最小费用int main() {#ifndef ONLINE_JUDGEfreopen("test.in","r",stdin);freopen("test.out","w",stdout);#endifscanf("%d",&t);while(t--){scanf("%d",&n);memset(dp,INF,sizeof(dp));for(int i=1;i<=n;i++){int m,b,p;scanf("%d",&m);for(int j=0;j<m;j++){scanf("%d%d",&b,&p);if(i==1){dp[i][b]=p;}else{for(int k=0;k<maxn;k++){if(dp[i-1][k]!=INF){//须保证带宽为k的设备存在if(k>b){dp[i][b]=min(dp[i][b],dp[i-1][k]+p);}else{dp[i][k]=min(dp[i][k],dp[i-1][k]+p);}}}}}}double res=0;for(int i=0;i<maxn;i++){if(dp[n][i]==INF) continue;double tmp=i*1.0/dp[n][i];if(tmp>res)res=tmp;}printf("%.3f\n",res);}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 1018Communication 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
- POJ 1018 Communication System
- poj 1018 Communication System
- POJ 1018 Communication System
- POJ 1018 Communication System
- 学习java的一些思路!
- 最大似然估计与最小二乘的解释
- C++ 列表初始化
- 【C++】C++常见面试题汇总,持续更新中...
- HTML5文件上传
- poj 1018 Communication System(DP)
- Java使用占位符拼接字符串
- ios 中Category类别
- OAF配置信息
- 学习java的一些理论也是很重要的!
- [Javascript] 怎么判断变量是否不为空
- 【0】Processing 学习
- Day1、Python
- Android安全专项-Apk加固