题意:手机在蜂窝网络中的定位是一个基本问题,假设蜂窝网络已经得知手机处于c1,c2,,,cn这些区域中的一个,最简单的方法是同时在这些区域中寻找手机,
但这样做很浪费带宽,由于蜂窝网络中可以得知手机在这不同区域中的概率,因此一个折中的办法就是把这些区域分成w组,然后依次访问,求最小的访问区域数的期望值。
析:dp[i][j] 表示第 i 个属于 j 组的期望最小值。
代码如下:
#pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set> #include <queue> #include <algorithm> #include <vector> #include <map> #include <cctype> #include <cmath> #include <stack> #include <unordered_map> #include <unordered_set> #define debug() puts("++++"); #define freopenr freopen("in.txt", "r", stdin) #define freopenw freopen("out.txt", "w", stdout) using namespace std; typedef long long LL; typedef pair<int, int> P; const int INF = 0x3f3f3f3f; const double inf = 0x3f3f3f3f3f3f; const double PI = acos(-1.0); const double eps = 1e-8; const int maxn = 100 + 5; const int mod = 2000; const int dr[] = {-1, 1, 0, 0}; const int dc[] = {0, 0, 1, -1}; const char *de[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"}; int n, m; const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; inline bool is_in(int r, int c){ return r >= 0 && r < n && c >= 0 && c < m; } int a[maxn]; int dp[maxn][maxn]; int sum[maxn]; int main(){ int T; cin >> T; while(T--){ scanf("%d %d", &n, &m); for(int i = 1; i <= n; ++i) scanf("%d", a+i); sort(a+1, a+n+1, greater<int>()); sum[0] = 0; for(int i = 1; i <= n; ++i) sum[i] = sum[i-1] + a[i]; memset(dp, INF, sizeof dp); memset(dp[0], 0, sizeof dp[0]); for(int i = 1; i <= n; ++i){ for(int j = 1; j <= m; ++j){ for(int k = j-1; k < i; ++k){ int t = dp[k][j-1] + (sum[i] - sum[k]) * i; dp[i][j] = min(dp[i][j], t); } } } printf("%.4f\n", (double)dp[n][m] / sum[n]); } return 0; }