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. C#.NET 如何快速输入一个对象事件对应的方法

    直接在Textbox图像对象中找到这个对象的KeyPress方法,然后输入触发的事件名称.效率更高,不容易出错. "void TypeAreaKeyPress(object sender, ...

  2. 复制class文件到as中出现非法字符,须要class,interface货enum

    问题如题,出现此情况是在导入eclipse项目到Android Studio出现这种错误, 非法字符: '\ufeff' 解决方式|错误: 须要class, interface或enum,查阅后了解到 ...

  3. [译]NUnit--Installation(三)

    Installation NUnit安装程序默认安装文件路径为C:\Program Files\NUnit 2.6.2.根据用户选择安装的选项,安装文件有三个子文件夹:bin.doc.samples. ...

  4. Java文件实时监控Commons-io

    今天看到一网友写的 Java 文件监控,实时监控文件加载 ,突然想到Commons-io中已有此功能的实现,先温习下 写个简单的Demo: 有三种方式: 1.java common.io    内部实 ...

  5. securecrt中vim行号下划线问题及SecureCRT里root没有高亮的设置,修改linux终端命令行颜色

      背景:在用raspberry用SecureCRT下的vim打开文件时出现用set nu时行有下划线,于是找了下解决办法,如下:vim行号下划线问题在vim中发现开启显示行号(set number) ...

  6. 使用IntelliJ IDEA 配置JDK(入门)

    一.JDK下载 首先要下载java开发工具包JDK,下载地址:http://www.oracle.com/technetwork/java/javase/downloads/index.html 点击 ...

  7. E20171102-E

    segment   n. 环节; 部分,段落; [计算机] (字符等的) 分段; [动物学] 节片; distinct  adj. 明显的,清楚的; 卓越的,不寻常的; 有区别的; 确切的;

  8. v-contextmenu的使用(右键菜单)

    先来个自己改写的图: 代码: 结构:<div class="wrap" v-contextmenu:contextmenu> <v-contextmenu ref ...

  9. 解决phpmyadmin数据文件导入有限制的问题(只能导入2M以下)

    修改配置php.ini文件中三个参数: 1.upload_max_filesize 2.memory_limit 3.post_max_size 建议根据实际需要进行设置.

  10. Extjs6 经典版 combo下拉框数据的使用及动态传参

    Extjs的下拉框,在点击的时候会请求一次数据,我们可不可以在点击前就请求好数据,让用户体验更好呢?答案当然是肯定的.如果是公用的下拉框还可以传入不同参数请求不同数据. 第一步: 进入页面前首先加载s ...