Communication System
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 28273   Accepted: 10074

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. 

Input

The first line of the input file contains a single integer t (1 ≤ t ≤ 10), the number of test cases, followed by the input data for each test case. Each test case starts with a line containing a single integer n (1 ≤ n ≤ 100), the number of devices in the communication system, followed by n lines in the following format: the i-th line (1 ≤ i ≤ n) starts with mi (1 ≤ mi ≤ 100), the number of manufacturers for the i-th device, followed by mi pairs of positive integers in the same line, each indicating the bandwidth and the price of the device respectively, corresponding to a manufacturer.

Output

Your program should produce a single line for each test case containing a single number which is the maximum possible B/P for the test case. Round the numbers in the output to 3 digits after decimal point. 

Sample Input

1 3
3 100 25 150 35 80 25
2 120 80 155 40
2 100 100 120 110

Sample Output

0.649

一道醉人题。。。输出时用printf("%.3f",res); 第一次做wa以为思路出现了偏差。。。然后换了个思路做了一遍。。。两次都卡了
好久。。。还有就是没有数据规模。。。 自己的思路:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stdlib.h>
using namespace std;
#define N 105 struct Dev
{
int width,price;
} dev[N][N]; Dev dp1[N][N];
double dp2[N][N]; int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,num[];
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d",&num[i]);
for(int j=; j<=num[i]; j++)
scanf("%d%d",&dev[i][j].width,&dev[i][j].price);
}
for(int i=; i<=num[]; i++)
{
dp1[][i].price=dev[][i].price;
dp1[][i].width=dev[][i].width;
dp2[][i]=dp1[][i].width/(double)dp1[][i].price;
}
for(int i=; i<=n; i++)
for(int j=; j<=num[i]; j++)
{
dp2[i][j]=;
for(int k=; k<=num[i-]; k++)
{
int width=min(dp1[i-][k].width,dev[i][j].width);
int price=dp1[i-][k].price+dev[i][j].price;
if(width/(double)price-dp2[i][j]>1e-)
{
dp2[i][j]=width/(double)price;
dp1[i][j].width=width;
dp1[i][j].price=price;
}
else if(abs(width/(double)price-dp2[i][j])<1e-)
{
if(width>dp1[i][j].width)
{
dp1[i][j].width=width;
dp1[i][j].price=price;
}
}
}
}
double res=;
for(int i=;i<=num[n];i++)
if(dp2[n][i]>res)
res=dp2[n][i];
printf("%.3f\n",res);
}
return ;
}
题解思路:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 105
#define INF 999999999 struct Dev
{
int width,price;
} dev[N][N]; int dp[N][]; int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(dp,,sizeof(dp));
int n,num[];
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d",&num[i]);
for(int j=; j<=num[i]; j++)
scanf("%d%d",&dev[i][j].width,&dev[i][j].price);
}
for(int i=;i<=n;i++)
for(int j=;j<=;j++)
dp[i][j]=INF;
for(int i=; i<=num[]; i++)
dp[][dev[][i].width]=min(dev[][i].price,dp[][dev[][i].width]);
for(int i=; i<=n; i++)
for(int j=; j<=num[i]; j++)
{
for(int k=; k<=; k++)
{
if(dp[i-][k]==INF)
continue;
if(k<=dev[i][j].width)
dp[i][k]=min(dp[i-][k]+dev[i][j].price,dp[i][k]);
else
dp[i][dev[i][j].width]=min(dp[i-][k]+dev[i][j].price,dp[i][dev[i][j].width]);
}
}
double res=;
for(int i=; i<=; i++)
{
if(dp[n][i]==INF)
continue;
//cout<<i/(double)dp[n][i]<<endl;
if(i/(double)dp[n][i]>res)
res=i/(double)dp[n][i];
}
printf("%.3f\n",res);
}
return ;
}
												

POJ_1018_(dp)的更多相关文章

  1. BZOJ 1911: [Apio2010]特别行动队 [斜率优化DP]

    1911: [Apio2010]特别行动队 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 4142  Solved: 1964[Submit][Statu ...

  2. 2013 Asia Changsha Regional Contest---Josephina and RPG(DP)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4800 Problem Description A role-playing game (RPG and ...

  3. AEAI DP V3.7.0 发布,开源综合应用开发平台

    1  升级说明 AEAI DP 3.7版本是AEAI DP一个里程碑版本,基于JDK1.7开发,在本版本中新增支持Rest服务开发机制(默认支持WebService服务开发机制),且支持WS服务.RS ...

  4. AEAI DP V3.6.0 升级说明,开源综合应用开发平台

    AEAI DP综合应用开发平台是一款扩展开发工具,专门用于开发MIS类的Java Web应用,本次发版的AEAI DP_v3.6.0版本为AEAI DP _v3.5.0版本的升级版本,该产品现已开源并 ...

  5. BZOJ 1597: [Usaco2008 Mar]土地购买 [斜率优化DP]

    1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4026  Solved: 1473[Submit] ...

  6. [斜率优化DP]【学习笔记】【更新中】

    参考资料: 1.元旦集训的课件已经很好了 http://files.cnblogs.com/files/candy99/dp.pdf 2.http://www.cnblogs.com/MashiroS ...

  7. BZOJ 1010: [HNOI2008]玩具装箱toy [DP 斜率优化]

    1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 9812  Solved: 3978[Submit][St ...

  8. px、dp和sp,这些单位有什么区别?

    DP 这个是最常用但也最难理解的尺寸单位.它与“像素密度”密切相关,所以 首先我们解释一下什么是像素密度.假设有一部手机,屏幕的物理尺寸为1.5英寸x2英寸,屏幕分辨率为240x320,则我们可以计算 ...

  9. android px转换为dip/dp

    /** * 根据手机的分辨率从 dp 的单位 转成为 px(像素) */ public int dipTopx(Context context, float dpValue) { final floa ...

随机推荐

  1. 《炉石传说》架构设计赏析(4):Asset管理

    欢迎转载,请注明作者[燕良@游戏开发]及原文地址:http://blog.csdn.net/neil3d/article/details/39580197 另外.欢迎大家来我的QQ群交流各种游戏引擎相 ...

  2. 浅析java(多方面解读)

    昨天我简单的说了一下我的编程学习之路.假设你热爱编程.而不是仅为了赚钱,我想我的经历或许会给你带来一定的启示,假设你还没有看.请先慢慢读完我的编程学习之路,您肯定会有还有一番体会的.. 好了.废话不多 ...

  3. Codeforces Round #233 (Div. 2)D. Painting The Wall 概率DP

                                                                                   D. Painting The Wall ...

  4. 【codeforces379F】 New Year Tree

    距离一个点最远的点一定是直径的一个端点.考虑运用这个原理,每次维护一下直径端点即可. #include<algorithm> #include<iostream> #inclu ...

  5. 第二次PHP面试题

    昨天下午翘班去参加了人生中第二次PHP面试.是一家相对第一家更加专业的互联网公司.效果不如第一家理想,笔试题有点难,而且偏高理论,面试时面试官也还不错,一起探讨,可是他的问题我还是很多都不知道,果然是 ...

  6. clojure学习记录

    take 从列表中获取子列表 into a b  把b conj 到a中 (defn count-a-seq [lat]  (reduce (fn [x y] (+ x 1)) 0 lat)) red ...

  7. YTU 2504: 蚂蚁感冒

    2504: 蚂蚁感冒 时间限制: 1 Sec  内存限制: 128 MB 提交: 273  解决: 118 题目描述 长100厘米的细长直杆子上有n只蚂蚁.它们的头有的朝左,有的朝右.每只蚂蚁都只能沿 ...

  8. MogileFS的实现和bug解决

    MogileFS的实现 准备三个主机: centos7.1:tracker节点.database节点.storage节点:192.168.213.251 centos7.2.centos7.3:sto ...

  9. “ResGen.exe”已退出,代码为 -1073741701 或 “ResGen.exe”已退出,代码为 2。

    解决的办法如下: 1.关闭所有Visual Studio: 2.以管理员的身份打开命令提示窗口:(开始-运行-cmd) 3.更改目录至"CD C:\Program Files (x86)\M ...

  10. Windows Java环境变量配置

    安装步骤略过... 环境变量配置 新建环境变量: JAVA_HOME C:\Program Files\Java\jdk1.6 将路径替换为自己的安装路径.    新建环境变量: classpath ...