关于证明可以参考题解http://codeforces.com/blog/entry/12739
就是将概率从大到小排序然后,然后从大到小计算概率
#include <iostream> #include <vector> #include <string> #include <algorithm> #include <functional> #include <cstdio> using namespace std; int main(){ int n; cin >> n; vector<double> p(n); for(int i = 0 ; i < n ; ++ i) cin>> p[i]; sort(p.begin(),p.end(), greater<double>()); double P=0 ,S=1.0, res = 0.0; if(1-p[0] < 1e-10) res = 1.0; else{ for(int i = 0 ; i < n; ++ i){ P +=p[i]/(1-p[i]); S *=(1-p[i]); res = max(res,P*S); } } printf("%.10f ",res); }