POJ 1018 Communication System
来源:互联网 发布:桔子数据库 编辑:程序博客网 时间:2024/05/02 01:20
Description
We have received an order from Pizoor Communications Inc. for a special communication system. The system consists of several devices. For each device, we are free to choose from several manufacturers. Same devices from two manufacturers differ in their maximum bandwidths and prices.
By overall bandwidth (B) we mean the minimum of the bandwidths of the chosen devices in the communication system and the total price (P) is the sum of the prices of all chosen devices. Our goal is to choose a manufacturer for each device to maximize B/P.
【题目分析】
比较有趣的一道DP题目。用DP[i][j] 来表示动态规划到了第i组的时候,而且带宽的最小值为j的时候。代价的最小值。然后就是显而易见的动态规划方程了:
dp[i][min(k,b)]=min(dp[i][min(k,b)],dp[i-1][k]+p);
然后需要注意一下初始化的过程i为1的情况需要特殊的处理一下,就可以了。
(特别庆祝7月份更博100篇)
【代码】
#include <cstdio>#include <cstring>#include <iostream>using namespace std;int dp[101][10001];int main(){ int tt,m,n,b,p; cin>>tt; while (tt--) { cin>>n; memset(dp,0x3f,sizeof dp); for (int i=0;i<3001;++i) dp[0][i]=0; for (int i=1;i<=n;++i) { cin>>m; for (int j=1;j<=m;++j) { cin>>b>>p; if (i==1) dp[1][b]=min(dp[1][b],p); else for (int k=0;k<3001;++k) dp[i][min(k,b)]=min(dp[i][min(k,b)],dp[i-1][k]+p); } } float ans=0; for (int i=1;i<=3001;++i) ans=max(ans,(float)i/(float)dp[n][i]); printf("%.3f\n",ans); }}
- 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# yyyyMMddHHmmss转yyyy-MM-dd HH:mm:ss
- datePicker
- opencv读取不同步双目视频并显示
- [2016/7/26][usaco 2.2]Runaround Numbers
- JavaScript中的this(你不知道的JavaScript)
- POJ 1018 Communication System
- 常用代码
- 我的Unity 3D之旅——Hello World(1)
- springMVC 基础注意
- OSG中抓取屏幕保存为图片
- 51Nod-1181-质数中的质数(质数筛法)
- 2.寻址和字节存储顺序
- Android Http POST请求
- BottomSheet的用法