POJ 1018 Communication System

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);
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值