【题解】:
【代码】:
1 #include <iostream> 2 #include <string.h> 3 #include <stdio.h> 4 #define inf 99999999 5 using namespace std; 6 int dp[105][10005];//i件设备,最小带宽(瓶颈)为j时的最小花费 7 int B[105][105]; 8 int P[105][105]; 9 int M[105],N; 10 double fmax(double a,double b){ 11 if(a>b) return a;else return b; 12 } 13 int main() 14 { 15 // freopen("out.txt","w",stdout); 16 int t; 17 scanf("%d",&t); 18 while(t--){ 19 scanf("%d",&N); 20 int MaxB=-1; 21 for(int i=1;i<=N;i++){ 22 scanf("%d",&M[i]); 23 for(int j=1;j<=M[i];j++){ 24 scanf("%d%d",&B[i][j],&P[i][j]); 25 MaxB=max(MaxB,B[i][j]); 26 } 27 } 28 for(int i=1;i<=N;i++){ 29 for(int j=0;j<=MaxB;j++) dp[i][j]=inf; 30 } 31 for(int i=0;i<=MaxB;i++) dp[0][i]=0; 32 33 for(int i=1;i<=N;i++){ 34 for(int j=1;j<=M[i];j++){ 35 int b=B[i][j],p=P[i][j]; 36 //dp[i+1][b]=max(dp[i+1][b],dp[i][b’]+p) 当前的b最小...其中b‘>=b 37 for(int bx=b;bx<=MaxB;bx++){ 38 dp[i][b]=max(dp[i][b],dp[i-1][bx]+p); 39 } 40 //dp[i+1][b‘]=max(dp[i+1][b‘],dp[i][b’]+p) 当前的b不是最小 ,其中b‘<=b 41 for(int bx=0;bx<=b;bx++){ 42 dp[i][bx]=min(dp[i][bx],dp[i-1][bx]+p); 43 } 44 } 45 } 46 double ans=-1; 47 for(int b=0;b<=MaxB;b++){ 48 ans=fmax(ans,(b+0.0)/dp[N][b]); 49 } 50 51 printf("%.3lf\n",ans); 52 } 53 54 return 0; 55 }
zoj1409 Communication System,布布扣,bubuko.com
原文:http://www.cnblogs.com/little-w/p/3775177.html