POJ 1018 Communication System(DP)
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)的更多相关文章
- POJ 1018 Communication System (动态规划)
We have received an order from Pizoor Communications Inc. for a special communication system. The sy ...
- POJ 1018 Communication System(贪心)
Description We have received an order from Pizoor Communications Inc. for a special communication sy ...
- POJ 1018 Communication System(树形DP)
Description We have received an order from Pizoor Communications Inc. for a special communication sy ...
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
- Communication System(动态规划)
个人心得:百度推荐的简单DP题,自己做了下发现真得水,看了题解发现他们的思维真得比我好太多太多, 这是一段漫长的锻炼路呀. 关于这道题,我最开始用DP的思路,找子状态,发现自己根本就不会找DP状态数组 ...
- POJ 3858 Hurry Plotter(DP)
Description A plotter is a vector graphics printing device that connects to a computer to print grap ...
- POJ - 2385 Apple Catching (dp)
题意:有两棵树,标号为1和2,在Tmin内,每分钟都会有一个苹果从其中一棵树上落下,问最多移动M次的情况下(该人可瞬间移动),最多能吃到多少苹果.假设该人一开始在标号为1的树下. 分析: 1.dp[x ...
- poj 1018 Communication System
点击打开链接 Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21007 Acc ...
- poj 1018 Communication System 枚举 VS 贪心
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21631 Accepted: ...
随机推荐
- filter push down
filter push down filter push down :先filter再做join 如果SQL里有where条件,那么数据库引擎会先filter再做join 但是MySQL5.6之前还不 ...
- Jquery-plugins-toastr-消息提示
toastr是一个基于jQuery简单.漂亮的消息提示插件,使用简单.方便,可以根据设置的超时时间自动消失. 1.使用很简单,首选引入toastr的js.css文件 html <link rel ...
- NYOJ-1073 最小值
http://acm.nyist.net/JudgeOnline/problem.php?pid=1073 # include<stdio.h> # include<stdlib.h ...
- 走进APICloud的世界 (1)
APICloud是什么东东?它是一个云端一体平台.啥意思?它利用HTML5跨平台技术同时满足android和ios的APP开发.相比APP传统开发而言,节约了不少成本,而且性能还可以和原生APP性能比 ...
- 高性能mysql第6章
第6章,优化配置 https://www.cnblogs.com/musings/p/5913157.html 1:服务器读取的配置文件,可以使用下面的命令查询 admin@iZwz92c0zpe8t ...
- iOS 开发笔记-plist使用
1.创建一个plist 2.填写为ImageList.plist 3.填入数据 4.完成 加载代码: @interface UYViewController () //图片信息的数组 @propert ...
- js五星好评
一般我们在一些购物以及美食的网站都会看到五星好评之类的,一下是使用js制作的五星好评! <!DOCTYPE html> <html lang="en"> & ...
- mac远程连接windows
第一步:在Mac上安装Remote Desktop Connection 进入Microsoft Remote Desktop Connection下载安装包. 下载完成之后,双击安装包进行安装. 第 ...
- Python: ValueError: too many values to unpack
eg1: >>>a,b=(1,2,3) Traceback (most recent call last): File "<stdin>",line ...
- java多线程----线程池源码分析
http://www.cnblogs.com/skywang12345/p/3509954.html 线程池示例 在分析线程池之前,先看一个简单的线程池示例. 1 import java.util.c ...