Test instructions: There are n devices, each device has a number of manufacturers, different manufacturers to provide equipment with different bandwidth and price, it is necessary for each device, the total bandwidth for the minimum bandwidth of these n devices, the total price for the sum of the price of these n devices, the maximum total bandwidth/Total price.
Solution: Enumeration + pruning. Enumerate the minimum bandwidth, sort all devices, prioritize b->p->id, two pruning: 1. Duplicate B does not require enumeration. 2. The current B does not meet the need to continue enumerating when all kinds of devices have a bandwidth greater than or equal to B.
Pruning effect tension pile ... Think it's because the data is a little weak? In short 32ms is over ... See the online puzzle has said DP ... Thought for a moment ... Did not say the scope of B ... I don't know how to Dp......orz.
Code:
#include <stdio.h> #include <iostream> #include <algorithm> #include <string> #include < string.h> #include <math.h> #include <limits.h> #include <time.h> #include <stdlib.h># include<map> #include <queue> #include <set> #include <stack> #include <vector> #define LL Long longusing namespace Std;struct node{int B, p, id; BOOL operator < (const node &TMP) const {if (b = = tmp.b) {if (p = = TMP.P) Return ID < tmp.id; return p < TMP.P; } return b < tmp.b; }}dev[10005];int Main () {int T; scanf ("%d", &t); while (t--) {int n; scanf ("%d", &n); int cnt = 0; for (int i = 0; i < n; i++) {int m; scanf ("%d", &m); while (m--) {int B, p; scanf ("%d%d", &b, &p); dev[cnt].b = b; DEV[CNT]. p = p; Dev[cnt++].id = i; }} sort (dev, dev + cnt); Double ans = 0.0; for (int i = 0; i < cnt; i++) {if (!i | | dev[i].b! = dev[i-1].b)//First Pruning { int now = dev[i].b;//The current enumeration of b int sumnum = 0, sum = 0;//The number of selected devices, Total price bool vis[105] = {0};//Have you chosen this Type device int price[105];//the lowest price memset for the condition in this device (prices, 0x3f3f3f3f, sizeof); for (int j = 0; J < CNT; J + +) {if (dev[j].b >= now) { if (!vis[dev[j].id]) {vis[dev[j].id] = 1; sumnum++; sum + = DEV[J].P; Price[dev[j].id] = DEV[J].P; } else {if (DEV[J].P < price[dev[j].id]) {Sum-= price[dev[j].id]; sum + = DEV[J].P; Price[dev[j].id] = DEV[J].P; }}}} if (sumnum = = N) ans = m Ax (ans, (double) now/sum); else break; }} printf ("%.3lf\n", ans); } return 0;}
POJ 1018 Communication System