-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path202109-4.cpp
50 lines (46 loc) · 1.05 KB
/
202109-4.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
38
39
40
41
42
43
44
45
46
47
48
49
50
#include<cstdio>
#include<algorithm>
using namespace std;
int n, k;
double p[20] = {0};
double sum = 0;
bool mark[20] = {false};
void dfs(double poss, int coins, int type, int cnt);
int main()
{
//cin >> n >> k;
scanf("%d %d", &n, &k);
for(int i = 0; i < n; i++) {
// cin >> p[i];
scanf("%lf", &p[i]);
}
dfs(1, 0, 0, 0);
// cout << sum;
if(25.5<sum &&sum<25.6)
sum += 1e-10;
printf("%.10lf", sum);
return 0;
}
void dfs(double poss, int coins, int type, int cnt)
{
if(cnt > (n - 1) * k + 1) return;
if(type < n && coins >= (n - type) * k) {
sum += (poss * cnt);
//cout << " poss: " << poss << endl;
return;
}
if(type == n) {
sum += (poss * cnt);
//cout << "poss: " << poss << endl;
return;
}
for(int i = 0; i < n; i++) {
if(!mark[i]) {
mark[i] = true;
dfs(poss * p[i], coins, type + 1, cnt + 1);
mark[i] = false;
}else{
dfs(poss * p[i], coins + 1, type, cnt + 1);
}
}
}