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);
}
}
本文介绍了一种使用动态规划(DP)解决特殊通讯系统配置问题的方法。目标是在多个设备中选择最佳组合以最大化整体带宽与总价格的比值。文章提供了详细的DP方程及代码实现。
469

被折叠的 条评论
为什么被折叠?



