#include <iostream>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
const int maxn = 107;
int n, w,dp[maxn][maxn],input[maxn],sum[maxn];
int main()
{
int t;
cin >> t;
while (t--) {
cin >> n >> w;
memset(dp, 0x3f, sizeof(dp));
sum[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> input[i];
}
sort(input + 1, input + n + 1,greater<int>());
for (int i = 1; i <= n; i++) {
sum[i] = sum[i - 1] + input[i];
}
for (int i = 0; i <= n; i++) dp[i][0] = 0;
for (int i = 1; i <= n; i++) {
dp[i][1] = i * sum[i];
for (int k = 2; k <= min(w,i); k++)
for (int j = 1; j < i; j++) {
dp[i][k] = min(dp[i][k], dp[j][k - 1] + i * (sum[i] - sum[j]));
}
}
cout << fixed << setprecision(4)<<dp[n][w] / double(sum[n]) << endl;
}
return 0;
}
08-10
158
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)