poj 1018 Communication System(DP)
2016-03-23 13:26
507 查看
题意:
一个通信系统需要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);
一个通信系统需要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_JUDGE freopen("test.in","r",stdin); freopen("test.out","w",stdout); #endif scanf("%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 [i]==INF) continue; double tmp=i*1.0/dp [i]; if(tmp>res) res=tmp; } printf("%.3f\n",res); } return 0; }
相关文章推荐
- html5文件上传
- android WebView加载html5介绍
- centos配置mutt跟msmtp发送邮件
- spring学习笔记(13)基于Schema配置AOP详解
- CSS边框盒子模型
- ListView常用小技巧
- 学习进度表
- mvc5 + ef6 + autofac搭建项目(四).1视屏上传生成截图
- Android 6.0敏感权限新特性及使用方法
- SharePoint2013 IT Professional - Anonymous Access 匿名访问
- 手机/移动前端开发需要注意的20个要点
- 学习java的一些思路!
- AngularJS Directive For Mouse Wheel Scroll Event
- centos直接yum安装nginx
- 学习进度表
- iOS开发中涉及的字体问题
- BIEE系统C组件启动不了 libxerces-c.so.28
- mysql 命令符操作登陆 展开 查看对象 查看数据表名称 数据表结构 插入
- hdoj-1166排兵布阵 简单的树状数组
- 我所理解的cocos2dx屏幕适配