#include <bits/stdc++.h> using namespace std; #define FOR(i,l,r) for(int i = (l); i <= (r); i++) #define FORD(i,l,r) for(int i = (l); i >= (r); i--) using num = double; using ind = long long; double prob_board[50'005]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); ind n,t; cin >> n >> t; vector<num> v; v.resize(n); FOR(i,1,n){ cin >> v[i-1]; } v.push_back(9); sort(v.begin(),v.end(), [](num a, num b){ return a > b; }); prob_board[0]=1; num wyn_max = 0; ind last_req = t + (n-t)/2 + ((n-t)%2); num after_last_req = 0; FOR(i,1,n){ num pnow = v[i]; num p_now = 1.0 - pnow; ind the_end = 1; the_end = max(the_end, last_req - (n-i)-2);//+n/5); ind the_begin = i; the_begin = min(the_begin, last_req); after_last_req += prob_board[last_req]*pnow; FORD(j,the_begin,the_end){ prob_board[j] = prob_board[j-1]*pnow + prob_board[j]*p_now; } prob_board[0] *= p_now; if(i < t) continue; num wyn_now = 0; FOR(j, t + ((i-t)/2) + ((i-t)%2),i){ wyn_now += prob_board[j]; } wyn_now += after_last_req; wyn_max = max(wyn_max, wyn_now); } //cout << std::setprecision(16) << std::fixed << wyn_max << '\n'; cout << std::setprecision(16) << std::fixed << wyn_max << '\n'; }
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 51 52 | #include <bits/stdc++.h> using namespace std; #define FOR(i,l,r) for(int i = (l); i <= (r); i++) #define FORD(i,l,r) for(int i = (l); i >= (r); i--) using num = double; using ind = long long; double prob_board[50'005]; int main(){ ios_base::sync_with_stdio(0); cin.tie(0); ind n,t; cin >> n >> t; vector<num> v; v.resize(n); FOR(i,1,n){ cin >> v[i-1]; } v.push_back(9); sort(v.begin(),v.end(), [](num a, num b){ return a > b; }); prob_board[0]=1; num wyn_max = 0; ind last_req = t + (n-t)/2 + ((n-t)%2); num after_last_req = 0; FOR(i,1,n){ num pnow = v[i]; num p_now = 1.0 - pnow; ind the_end = 1; the_end = max(the_end, last_req - (n-i)-2);//+n/5); ind the_begin = i; the_begin = min(the_begin, last_req); after_last_req += prob_board[last_req]*pnow; FORD(j,the_begin,the_end){ prob_board[j] = prob_board[j-1]*pnow + prob_board[j]*p_now; } prob_board[0] *= p_now; if(i < t) continue; num wyn_now = 0; FOR(j, t + ((i-t)/2) + ((i-t)%2),i){ wyn_now += prob_board[j]; } wyn_now += after_last_req; wyn_max = max(wyn_max, wyn_now); } //cout << std::setprecision(16) << std::fixed << wyn_max << '\n'; cout << std::setprecision(16) << std::fixed << wyn_max << '\n'; } |