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. HDU 1796 How many integers can you find(容斥原理+二进制/DFS)

    How many integers can you find Time Limit: 12000/5000 MS (Java/Others)    Memory Limit: 65536/32768 ...

  2. openstack (1)----- NTP 时间同步服务

    一.标准时间 1.地球分为东西十二个区域,共计24个时区 2.格林威治作为全球标准时间即(GMT时间),东时区以格林威治时区进行加,而西时区则进行减 3.地球的轨道并非正圆,在加上自传速度逐年递减,因 ...

  3. maven 打包排除配置文件

    如果你想通过pom.xml文件的配置实现的话,你可以这样1.打jar包时过滤配置文件<build><!-- 过滤配置文件 --><resources><res ...

  4. Python正則表達式小结(1)

    学习一段python正則表達式了, 对match.search.findall.finditer等函数作一小结  以下以一段网页为例,用python正則表達式作一个范例: strHtml = '''& ...

  5. easyUI的下拉框combobox与树tree联动

    参与联动的有 2 个combobox 和 1 个tree: <input id="combobox1" class="easyui-combobox" n ...

  6. 关于clojurescript+phantomjs+react的一些探索

    这两天需要使用phantomjs+react生成些图片 React->Clojurescript: 最开始发现clojurescript中包裹react的还挺多: https://github. ...

  7. rabbitmq最大连接数(Socket Descriptors)

    RabbitMQ自带了显示能够接受的最大连接数,有2种比较直观的方式:1. rabbitmqctl命令. 1 2 3 4 5 6 7 8 9 10 11 12 <span style=" ...

  8. C#调用Oracle存储过程的方法

    C#调用Oracle存储过程的方法 准备: 环境:pl/sql+oracle9i+vs2008 创建表test: create table TEST(  ID      NUMBER,//编号  NA ...

  9. 转 source insight 复制后光标在前面

    source insight 里编辑的时候,每次粘贴后,光标停留在粘贴内容的前面. 我想把它设定为 粘贴后,光标移动倒粘贴内容的后面. 怎么做? 这是个设置问题,按照下面的步骤设定就可以了. Opti ...

  10. SAM入门

    学了两天,会了点皮毛,这里只放代码. P3804 #include<iostream> #include<cstdio> #include<cmath> #incl ...