poj 1018
来源:互联网 发布:怎么查淘宝客 编辑:程序博客网 时间:2024/05/29 03:06
动态规划,看着被人的题解做的,还是有个疑问 ,就是带宽的最大值是怎么确定的,题目只说明是一个整数。
状态转移方程 :
dp[i][b] :其中i表示选取前i个公司的产品,b表示当前第i个公司从0 到最大值的带宽。dp[i][b]表示选取了前i个公司产品的价格。
如果
k :1 to max
if(k<=b) dp[i][k]=min(dp[i][k],dp[i-1][k]+p);
else dp[i][b]=min(dp[i][b],dp[i-1][k]+p);
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int inf=0x3f3f3f3f;int dp[102][1001];int main(){ int t; cin>>t; int b,p; int i,j,k; int n; int c; while(t--) { cin>>n; for(i=0;i<=n;i++) for(j=0;j<1005;j++) { dp[i][j]=inf; } for(i=1;i<=n;i++) { cin>>c; for(j=0;j<c;j++) { cin>>b>>p; if(i==1) { dp[1][b]=min(dp[1][b],p); } else { for(k=0;k<1001;k++) { if(dp[i-1][k]!=inf) { if(k<=b) dp[i][k]=min(dp[i][k],dp[i-1][k]+p); else dp[i][b]=min(dp[i][b],dp[i-1][k]+p); } } } } } double ans=0; for(i=0;i<1001;i++) { if(dp[n][i]!=inf) { ans=max(i*1.0/dp[n][i],ans); } } printf("%.3f\n",ans); } return 0;}
0 0
- POJ 1018
- poj 1018
- POJ 1018
- POJ-1018
- poj 1018
- POJ 1018
- poj 1018
- 【POJ】1018
- poj 1018
- poj 1018
- poj 1018
- poj 1018
- POJ-1018
- poj 1018
- POJ 1018
- POJ-1018
- poj 1018 Communication System
- POJ 1018 Communication System
- Linux学习十七、正规表达式练习题
- 【OpenGL】关于OpenGL中glBindTexture函数的理解
- poj 3090 (欧拉函数,找规律)
- Android 实现横向滑动效果
- Activity传输自定义数组参数list的方法
- poj 1018
- jquery mobile checkbox取消选择与选择
- 更改数据库表所有者(前缀)例如[dbo].
- AppiumDriver升级到2.0.0版本引发的问题--Cannot instantiate the type AppiumDriver
- Ajax简单程序,使用ajax和servlet简单校验email地址
- 将pdf有效的转换成ppt的方法
- 自定义dialog
- 如何设置 tabbar的 选中图标的颜色
- Android 4.4中的距离/接近传感器 P-sensor(一)