#include <bits/stdc++.h>
using namespace std;
int n, d, x;
long double w[15], tot, dp[(1 << 15)][16], y;
int main() {
cin >> n >> d;
for (int i = 0; i < n; i ++ ) cin >> w[i], tot += w[i];
tot /= (long double)d;
for (int i = 0; i < (1 << n); i ++ , y = 0) {
for (int j = 0; j < n; j ++ ) y += ((bool)(i & (1 << j))) * w[j];
dp[i][1]=pow(y-tot,2);
for(int j=2;j<=d;j++){
dp[i][j]=dp[i][j-1]+dp[0][1];
x=i;
while(x>0){
dp[i][j]=min(dp[i][j],dp[i-x][j-1]+dp[x][1]);
x=(x-1)&i;
}
}
}
printf("%.15Lf", (dp[(1<<n)-1][d]/((long double)d)));
}
[ABC332E] Lucky bag
最新推荐文章于 2024-11-04 21:39:11 发布