Communication System

题意:一个系统由n个设备组成,每个设备可以由mi个厂商提供,每个设备你可以选一个厂商,在你选定的厂商的设备中,b(带宽)是所选设备中b值最小的,类似于短板效应,p是所有价格之和,要求b/p最小。(看了很久才懂了题意,~~~要史了)

题解:dp[ i ][ j ]表示选了i个设备,带宽最小为j所用到的最小花费。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<iostream>
 4 #include<algorithm>
 5 using namespace std;
 6
 7 const int INF=1e8;
 8
 9 int kase,n,m;
10 int dp[105][1005];
11
12 void Inite(){
13     for(int i=0;i<105;i++)
14         for(int j=0;j<1005;j++) dp[i][j]=INF;
15 }
16
17 void Print(){
18     double ans=0;
19     for(int i=1;i<1005;i++) if(dp[n][i]!=INF) ans=max(ans,(double)i/(double)dp[n][i]);
20     printf("%.3lf\n",ans);
21 }
22
23 void Solve(){
24     cin>>n;
25     for(int i=1;i<=n;i++){
26         cin>>m;
27         for(int j=1;j<=m;j++){
28             int a,b;
29             scanf("%d%d",&a,&b);
30             if(i==1){ dp[1][a]=b; continue;}
31             for(int k=0;k<1005;k++){
32                 if(dp[i-1][k]!=INF){
33                     if(k<=a) dp[i][k]=min(dp[i][k],dp[i-1][k]+b);
34                     else dp[i][a]=min(dp[i][a],dp[i-1][k]+b);
35                 }
36             }
37         }
38     }
39     Print();
40 }
41
42 int main()
43 {   cin>>kase;
44     while(kase--){
45         Inite();
46         Solve();
47     }
48     return 0;
49 }
时间: 2024-11-18 02:17:27

Communication System的相关文章

POJ 1018 Communication System 题解

本题一看似乎是递归回溯剪枝的方法,我一提交,结果超时. 然后又好像是使用DP,还可能我剪枝不够. 想了很久,无奈忍不住偷看了下提示,发现方法真多,有贪心,DP,有高级剪枝的,还有三分法的,八仙过海各显神通啊. 坏习惯了,没思考够深入就偷看提示了. 幸好及时回头,还不需要看别人的代码了.自己做出来之后,有空看看多种解法的代码也好. 然后我想出自己的思路了,使用贪心,剪枝,DP综合优化下,呵呵,最后程序有点复杂,优化到了16ms,运气好点,或者vector换成原始数组的话,应该可以0MS了. 总体思

zoj1409 Communication System

[题解]: [代码]: 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(

poj1018 Communication System

Description We have received an order from Pizoor Communications Inc. for a special communication system. The system consists of several devices. For each device, we are free to choose from several manufacturers. Same devices from two manufacturers d

POJ 1018 Communication System (动态规划)

Communication System Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22500   Accepted: 8008 Description We have received an order from Pizoor Communications Inc. for a special communication system. The system consists of several devices.

poj 1018 Communication System (枚举)

Communication System Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22380   Accepted: 7953 Description We have received an order from Pizoor Communications Inc. for a special communication system. The system consists of several devices.

F - Communication System

We have received an order from Pizoor Communications Inc. for a special communication system. The system consists of several devices. For each device, we are free to choose from several manufacturers. Same devices from two manufacturers differ in the

POJ 1018 Communication System(DP)

http://poj.org/problem?id=1018 题意: 某公司要建立一套通信系统,该通信系统需要n种设备,而每种设备分别可以有m1.m2.m3.....mn个厂家提供生产,而每个厂家生产的同种设备都会存在两个方面的差别:带宽bandwidths 和 价格prices. 现在每种设备都各需要1个,考虑到性价比问题,要求所挑选出来的n件设备,要使得B/P最大. 其中B为这n件设备的带宽的最小值,P为这n件设备的总价. 思路:DP解决. d[i][j]代表选择第i个设备时最小带宽j时的价

贪心/poj 1018 Communication System

1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int INF=0xfffffff; 6 struct node 7 { 8 int b,p; 9 }; 10 node a[110][110]; 11 int m[110]; 12 int pmin,psum,bmax,n; 13 double ans; 14 int main() 15

POJ 1018 Communication System

题意:有n种设备,每种设备都有若干制造商,不同制造商提供设备的带宽和价格不同,现需要每种设备各一个,总带宽为这n个设备的最小带宽,总价格为这n个设备的价格之和,求最大的总带宽/总价格. 解法:枚举+剪枝.枚举最小带宽,将所有设备进行排序,排序的优先级为b->p->id,两个剪枝:1.重复的b不需要枚举.2.当前的b无法满足让所有种类的设备都有设备的带宽大于等于b的时候不需要继续枚举. 剪枝效果拔群……觉得是因为数据有点弱?总之32ms就过了……看到网上题解有说dp的……想了一下……没说b的范围

POJ - 1018 Communication System (暴力)

题目大意:要买n个零件,每个零件可以由m个厂家提供,每个零件都有相应的b值和p值.(每个零件只能买一个)现在要求你求出最大的min(b) /sum(p) min(b)表示的是每个零件的最小b值 sum(p)表示的是每个零件的p值的和 解题思路:直接暴力 #include<cstdio> #include<algorithm> #include<cstring> using namespace std; #define maxn 110 struct device{ in