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个人中 和 ...
随机推荐
- Java——Read/convert an InputStream to a String
获取 InputStream 并将其转换为String的简单方法. 添加commons-io-2.4.jar import java.io.IOException; import java.io.In ...
- mysql 服务端事务和客户端事务对比分析
之前做mysql事务测试的时候都是在mysql服务端存储过程里面包含事务. 例如: CREATE DEFINER=`root`@`localhost` PROCEDURE `Test`(out deb ...
- 【BZOJ4869】相逢是问候 [线段树][欧拉定理]
相逢是问候 Time Limit: 40 Sec Memory Limit: 512 MB[Submit][Status][Discuss] Description Informatikverbin ...
- gdoi2017
今年的gdoi第一天t1大水题一道 裸的kmp 但是 我把记录长度的int数组开成了char类型 正解变爆零 心态爆炸......... 后面的第二题两千字题目以及五千字附加故事(我是没有去看,据说全 ...
- bzoj 1588 bst
用set存下就好了. /************************************************************** Problem: 1588 User: BLADE ...
- word 宏,脚本编程
'脚本方式新建word 再新建文档,文档中输入字符串"你好" Dim wdapp As Word.Application Dim wddoc As Word.Document Se ...
- git 配置多用户
.ssh 下的 config.txt 内容 # 配置github.com Host github.com HostName github.com IdentityFile ~/.ssh/id_rsa_ ...
- bootstrap-table组合表头
1.效果图 2.html代码 <table id="table"></table> 3.javascript代码 $("#table") ...
- perl6 修改文件并覆盖
use v6; my $filename = 'data.txt'; my $data = slurp $filename; say $data; $data ~~ s/'4'/'ABC'/; say ...
- Bookmarks_www2
Bookmarks Bookmarks alexis- (Alex Incogito) - Repositories · GitHub GitHub - aetcnc-Arduino_DeltaHMI ...