poj 1018(dp)
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 25653 | Accepted: 9147 |
Description
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
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
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 思路:定义dp[i][j]为前i个设备的容量为j的最小费用;
状态转移方程为:dp[i][j]=min(dp[i][j],dp[i-1][j]+p);
边界:dp[1][j]=p;
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define PI 3.141592653589792128462643383279502
const int inf=0x3f3f3f3f;
int t,n,j,ss,m[][];
int main(){
//#ifdef CDZSC_June
//freopen("in.txt","r",stdin);
//#endif
//std::ios::sync_with_stdio(false);
scanf("%d",&t);
while(t--){
scanf("%d",&n);
memset(m,0x3f,sizeof(m));
for(int i=;i<=n;i++){
int num;
scanf("%d",&num);
for(j=;j<=num;j++){
int b,p;
scanf("%d%d",&b,&p);
if(i==){m[][b]=min(m[][b],p);}
else {
for(int k=;k<;k++){
if(m[i-][k]!=inf){
if(k<=b)
m[i][k]=min(m[i][k],m[i-][k]+p);
else
m[i][b]=min(m[i][b],m[i-][k]+p);
}
}
}
}
}
double ans=;
for(int i=;i<;i++){
if(m[n][i]!=inf){
double k=(double)i/m[n][i];
if(k>ans) ans=k;
}
}
printf("%.3lf\n",ans);
}
return ;
}
poj 1018(dp)的更多相关文章
- POJ 1018 Communication System(树形DP)
Description We have received an order from Pizoor Communications Inc. for a special communication sy ...
- POJ 1018 Communication System(DP)
http://poj.org/problem?id=1018 题意: 某公司要建立一套通信系统,该通信系统需要n种设备,而每种设备分别可以有m1.m2.m3.....mn个厂家提供生产,而每个厂家生产 ...
- hdu 1513 && 1159 poj Palindrome (dp, 滚动数组, LCS)
题目 以前做过的一道题, 今天又加了一种方法 整理了一下..... 题意:给出一个字符串,问要将这个字符串变成回文串要添加最少几个字符. 方法一: 将该字符串与其反转求一次LCS,然后所求就是n减去 ...
- poj 1080 dp如同LCS问题
题目链接:http://poj.org/problem?id=1080 #include<cstdio> #include<cstring> #include<algor ...
- lightoj 1018 dp
题目链接:http://lightoj.com/volume_showproblem.php?problem=1018 #include <cstdio> #include <cst ...
- poj 1609 dp
题目链接:http://poj.org/problem?id=1609 #include <cstdio> #include <cstring> #include <io ...
- POJ 1037 DP
题目链接: http://poj.org/problem?id=1037 分析: 很有分量的一道DP题!!! (参考于:http://blog.csdn.net/sj13051180/article/ ...
- POJ 1018 【枚举+剪枝】.cpp
题意: 给出n个工厂的产品参数带宽b和价格p,在这n个工厂里分别选1件产品共n件,使B/P最小,其中B表示n件产品中最小的b值,P表示n件产品p值的和. 输入 iCase n 表示iCase个样例n个 ...
- Jury Compromise POJ - 1015 dp (标答有误)背包思想
题意:从 n个人里面找到m个人 每个人有两个值 d p 满足在abs(sum(d)-sum(p)) 最小的前提下sum(d)+sum(p)最大 思路:dp[i][j] i个人中 和 ...
随机推荐
- JVM-内存回收算法--复制算法
复制算法,它将堆上的内存分为两个大小相等的区域,一个是空闲区域,一个是活动区域.在程序运行中,实际使用的是活动区域,也就是有50%的空间被浪费掉. 复制算法的实现过程:1.找出活动空间中所有存活的对象 ...
- 【hdu1255】线段树求矩形面积交
题意大概就是上图这个样子.<=100组测试数据,每组<=1000个矩形. 题解: 这个问题怎么解决..做了上一题矩形面积并应该就会了.. 对于每个节点维护3个值: cnt:该节点所代表的这 ...
- 【BZOJ】1477 青蛙的约会
[算法]扩展欧几里德算法(模线性方程) [题解]http://hzwer.com/2121.html 一些问题写在http://www.cnblogs.com/onioncyc/p/6146143.h ...
- python初步学习-pycharm使用
Pycharm简介 PyCharm是一种Python IDE,带有一整套可以帮助用户在使用Python语言开发时提高其效率的工具,比如调试.语法高亮.Project管理.代码跳转.智能提示.自动完成. ...
- Microsoft Visual Studio TFS 切换登录用户的方法
方法一 用VS2012开发项目,一直困扰着我的是不知道怎么去切换TFS的登录帐户,因为每次TFS都是用默认的账户连接到TFS服务器,有时想切换另一个用户登录TFS服务器, 不知道从何下手,今天总算找到 ...
- js中字符串的操作
1.length 获取字符串长度 var str = "hello world"; alert(str); 2.索引 通过下标获取字符串指定位置的字符,但是不能改变该索引对应的值 ...
- python进行EDA探索性数据分析
1.查看数据的类型概况 cols = [c for c in train.columns] #返回数据的列名到列表里 print('Number of features: {}'.format(l ...
- ctsc&apio2018八日游
day0: 早就知道自己是打酱油的..早就做好了打铁的准备.. Q:那你来干嘛 A:当然是来玩啊!!玩啊!啊!! emmmmm 抱着半期考不及格的卷子瑟瑟发抖地上了飞机. day1:报道!当然还有在宾 ...
- perl中的lock
#!/usr/bin/env perl -w use strict; use threads; use threads::shared; ; print "count的起始值为:$count ...
- python基础===Sublime Text 3 快捷键
选择类 Ctrl+D 选中光标所占的文本,继续操作则会选中下一个相同的文本. Alt+F3 选中文本按下快捷键,即可一次性选择全部的相同文本进行同时编辑.举个栗子:快速选中并更改所有相同的变量名.函数 ...