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个人中 和 ...
随机推荐
- google protobuf序列化原理解析 (PHP示例)
一.简介 Protocol Buffers是谷歌定义的一种跨语言.跨平台.可扩展的数据传输及存储的协议,因为将字段协议分别放在传输两端,传输数据中只包含数据本身,不需要包含字段说明,所以传输数据量小, ...
- MYSQL查找总结
a.条件判断where select * from 表 where id > 1 and name != 'alex' and num = 12; select * from 表 where ...
- 【洛谷 P4180】【模板】严格次小生成树[BJWC2010](倍增)
题目链接 题意如题. 这题作为我们KS图论的T4,我直接打了个很暴力的暴力,骗了20分.. 当然,我们KS里的数据范围远不及这题. 这题我debug了整整一个晚上还没debug出来,第二天早上眼前一亮 ...
- MongoDB 数据库(1)
数据库 MongoDB (芒果数据库) 数据存储阶段 文件管理阶段 (.txt .doc .xls) 优点 : 数据可以长期保存 可以存储大量的数据 使用简单 缺点 : 数据一致性差 数据查找修改不方 ...
- DirectX介绍(转)
原文转自 https://baike.baidu.com/item/Direct3D/910353
- mysql 之修改初始密码
转载自:https://www.cnblogs.com/ivictor/p/5142809.html 为了加强安全性,MySQL5.7为root用户随机生成了一个密码,在error log中,关于er ...
- Linux-进程间通信(五): 网络套接字
不想说话,坑太深:持续学习网络编程中...
- openssl-0.9.8y
openssl-0.9.8y 支持 32位和64位 编译不报错和向上兼容和向下兼容. http://www.openssl.org/source/openssl-0.9.8y.tar.gz https ...
- 使用cURL POST上传文件
使用cURL POST上传文件 http://blog.csdn.net/v6543210/article/details/20152575
- caffe Python API 之激活函数ReLU
import sys import os sys.path.append("/projects/caffe-ssd/python") import caffe net = caff ...