Communication System
Time Limit: 1000MS |
|
Memory Limit: 10000K |
Total Submissions: 25653 |
|
Accepted: 9147 |
Description
We have the received an order from Pizoor Communications Inc. for a special communication system. The system consists of several devices. For each device, we is free to choose from several manufacturers. Same devices from the 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 T Otal Price (P) was the sum of the prices of all chosen devices. Our goal are 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 is starts with a line containing a single integer n (1≤n≤100) and 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 O F manufacturers for the i-th device, followed by mi pairs of positive integers on the same line, each indicating the BANDW Idth 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 33 100 25 150 35 80 252 120 80 155 402 100 100 120 110
Sample Output
0.649
Train of thought: Define DP[I][J] for the minimum cost of the capacity of the first I equipment J;
The state transition equation is: dp[i][j]=min (dp[i][j],dp[i-1][j]+p);
Boundary: dp[1][j]=p;
1#include <iostream>2#include <cstdio>3#include <algorithm>4#include <cstring>5#include <cstdlib>6#include <iomanip>7#include <cmath>8#include <vector>9#include <queue>Ten#include <stack> One using namespacestd; A #definePI 3.141592653589792128462643383279502 - Const intinf=0x3f3f3f3f; - intt,n,j,ss,m[ -][ -]; the intMain () { - //#ifdef Cdzsc_june - //freopen ("In.txt", "R", stdin); - //#endif + //Std::ios::sync_with_stdio (false); -scanf"%d",&t); + while(t--){ Ascanf"%d",&n); atMemset (M,0x3f,sizeof(m)); - for(intI=1; i<=n;i++){ - intnum; -scanf"%d",&num); - for(j=1; j<=num;j++){ - intb,p; inscanf"%d%d",&b,&p); - if(i==1) {m[1][b]=min (m[1][b],p);} to Else { + for(intk=0;k< -; k++){ - if(m[i-1][k]!=inf) { the if(k<=b) *M[i][k]=min (m[i][k],m[i-1][k]+p); $ ElsePanax NotoginsengM[i][b]=min (m[i][b],m[i-1][k]+p); - } the } + } A } the } + Doubleans=0; - for(intI=0;i< -; i++){ $ if(m[n][i]!=inf) { $ DoubleK= (Double) i/M[n][i]; - if(K>ans) ans=K; - } the } -printf"%.3lf\n", ans);Wuyi } the return 0; -}
POJ 1018 (DP)