-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path202109-4-1.cpp
37 lines (36 loc) · 985 Bytes
/
202109-4-1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* @file 202109-4-1.cpp
* @author zyh
* @brief Solution 1, 100 points.
*/
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char** argv)
{
int n, k;
scanf("%d%d", &n, &k);
vector<double> pr(n);
for (int i = 0; i < n; i++) {
scanf("%lf", &pr[i]);
}
vector<vector<double> > dp(1 << n, vector<double>((n - 1) * k + 2));
double ans = 0;
dp[0][0] = 1;
for (int i = 0; i < (1 << n); i++) {
for (int j = 0; j <= (n - 1) * k; j++) {
int cnt = __builtin_popcount(i);
if (cnt + j / k >= n) {
ans += dp[i][j] * (cnt + j);
} else {
for (int t = 0; t < n; t++) {
if (i & (1 << t)) {
dp[i][j + 1] += dp[i][j] * pr[t];
} else {
dp[i | (1 << t)][j] += dp[i][j] * pr[t];
}
}
}
}
}
printf("%.10f\n", ans);
}