http://poj.org/problem?id=1018

题意:

某公司要建立一套通信系统,该通信系统需要n种设备,而每种设备分别可以有m1、m2、m3、...、mn个厂家提供生产,而每个厂家生产的同种设备都会存在两个方面的差别:带宽bandwidths 和 价格prices。

现在每种设备都各需要1个,考虑到性价比问题,要求所挑选出来的n件设备,要使得B/P最大。

其中B为这n件设备的带宽的最小值,P为这n件设备的总价。

思路:DP解决。

d[i][j]代表选择第i个设备时最小带宽j时的价格。

状态转移方程就是d[i][j]=min{d[i-1][k]+p,d[i][j]}。

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std; const int INF = 0x3f3f3f3f;
const int maxn = + ; int n,m; int dp[maxn][]; int main()
{
//freopen("D:\\txt.txt", "r", stdin);
int t, b, p;
cin >> t;
while (t--)
{
memset(dp, INF, sizeof(dp));
cin >> n;
for (int i = ; i < n; i++)
{
cin >> m;
for (int j = ; j < m; j++)
{
cin >> b >> p;
if (i == )
dp[i][b] = p;
else
{
for (int k = ; k < ; k++)
{
if (dp[i - ][k] != INF)
{
if (k <= b)
dp[i][k] = min(dp[i - ][k] + p, dp[i][k]);
else
dp[i][b] = min(dp[i - ][k] + p, dp[i][b]);
}
}
}
}
}
double ans = ;
for (int k = ; k < ; k++)
{
if (dp[n - ][k] != INF)
{
double c = (double)k / dp[n - ][k];
if (c>ans) ans = c;
}
}
cout << setiosflags(ios::fixed) << setprecision() << ans << endl;
}
return ;
}

POJ 1018 Communication System(DP)的更多相关文章

  1. POJ 1018 Communication System (动态规划)

    We have received an order from Pizoor Communications Inc. for a special communication system. The sy ...

  2. POJ 1018 Communication System(贪心)

    Description We have received an order from Pizoor Communications Inc. for a special communication sy ...

  3. POJ 1018 Communication System(树形DP)

    Description We have received an order from Pizoor Communications Inc. for a special communication sy ...

  4. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  5. Communication System(动态规划)

    个人心得:百度推荐的简单DP题,自己做了下发现真得水,看了题解发现他们的思维真得比我好太多太多, 这是一段漫长的锻炼路呀. 关于这道题,我最开始用DP的思路,找子状态,发现自己根本就不会找DP状态数组 ...

  6. POJ 3858 Hurry Plotter(DP)

    Description A plotter is a vector graphics printing device that connects to a computer to print grap ...

  7. POJ - 2385 Apple Catching (dp)

    题意:有两棵树,标号为1和2,在Tmin内,每分钟都会有一个苹果从其中一棵树上落下,问最多移动M次的情况下(该人可瞬间移动),最多能吃到多少苹果.假设该人一开始在标号为1的树下. 分析: 1.dp[x ...

  8. poj 1018 Communication System

    点击打开链接 Communication System Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21007   Acc ...

  9. poj 1018 Communication System 枚举 VS 贪心

    Communication System Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21631   Accepted:  ...

随机推荐

  1. Mac下PHP7.1+Nginx安装和配置

    https://blog.csdn.net/haiyanggeng/article/details/79186982 PHP:7.1.13Nginx:1.12.2 1. 安装PHP# 添加源brew ...

  2. [py]监控内存并出图

    监控内存出图 先将内存数据搞到数据库 已使用内存算法 used = int(total) - int(free) - int(butffers) - int(cache) pymysql模块使用 db ...

  3. 实习培训——Java基础(2)

    实习培训——Java基础(2) 1  Java 变量类型 在Java语言中,所有的变量在使用前必须声明.声明变量的基本格式如下: type identifier [ = value][, identi ...

  4. 【SVM】A Practical Guide to Support Vector Classi cation

    零.简介 一般认为,SVM比神经网络要简单. 优化目标:

  5. [LeetCode] 532. K-diff Pairs in an Array_Easy tag: Hash Table

    Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in t ...

  6. .net 调用API并解析Json数据方法

    using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using Syst ...

  7. 软件包管理:yum在线管理-yum命令

    只要我们的电脑可以接入互联网,那么yum源就是配好的,yum命令可以直接使用. 列出的是服务器上全部的rpm包. 包名,包全名的概念只在rpm手动管理时有用. 关键字主要指包名,只要知道了关键字就可以 ...

  8. javascript的Object对象的defineProperty和defineProperties

    Object的属性 查看官网:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Obje ...

  9. STA分析(一) setup and hold

    timing check可以分为Dynamic Timing Analysis(Post_sim)和Static Timing Analysis STA:可以分析的很全面:仿真速度也很快:可以分析控制 ...

  10. app加密算法

    php端 <?phpnamespace app\controllers;use yii\web\Controller;class TestController extends Controlle ...