#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
int t,n;
double p;
int main() {
std::ios_base::sync_with_stdio(0);
std::cin.tie(NULL);
std::cin>>n>>t;
std::vector<double> pr;
for(int i=0;i<n;i++){
std::cin>>p;
pr.emplace_back(p);
}
sort(pr.begin(),pr.end(),std::greater<double>());
std::vector<double> pro[2];
pro[0].resize(37510,0);
pro[1].resize(37510,0);
if(t%2==1){
pro[0][12500]=pr[0];
pro[0][12500-1]=1-pr[0];
}
else
pro[0][12500]=1;
int ko=1;
double result=0;
int sta=12500-1;
int end=12500;
for(int i=t%2;i<n-1;i+=2){
double padd=pr[i]*pr[i+1];
double psub=(1-pr[i])*(1-pr[i+1]);
double psame=1-padd-psub;
if(pro[!ko][end]<10e-16)
end--;
if(pro[!ko][end]>10e-16)
end++;
if(pro[!ko][sta]<10e-16)
sta++;
if(sta>1)
if(pro[!ko][sta]>10e-16)
sta--;
for(int j=sta;j<=end;j++)
pro[ko][j]=pro[!ko][j-1]*padd+pro[!ko][j]*psame+pro[!ko][j+1]*psub;
double can=0;
for(int j=t/2+12500;j<=end;j++)
can+=pro[ko][j];
if(can>result)
result=can;
//std::cout<<std::fixed()<<can<<std::endl;
ko=!ko;
}
std::cout<<std::fixed<<std::setprecision(14)<<result;
}
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 53 54 55 56 57 58 59 | #include <iostream> #include <vector> #include <algorithm> #include <iomanip> int t,n; double p; int main() { std::ios_base::sync_with_stdio(0); std::cin.tie(NULL); std::cin>>n>>t; std::vector<double> pr; for(int i=0;i<n;i++){ std::cin>>p; pr.emplace_back(p); } sort(pr.begin(),pr.end(),std::greater<double>()); std::vector<double> pro[2]; pro[0].resize(37510,0); pro[1].resize(37510,0); if(t%2==1){ pro[0][12500]=pr[0]; pro[0][12500-1]=1-pr[0]; } else pro[0][12500]=1; int ko=1; double result=0; int sta=12500-1; int end=12500; for(int i=t%2;i<n-1;i+=2){ double padd=pr[i]*pr[i+1]; double psub=(1-pr[i])*(1-pr[i+1]); double psame=1-padd-psub; if(pro[!ko][end]<10e-16) end--; if(pro[!ko][end]>10e-16) end++; if(pro[!ko][sta]<10e-16) sta++; if(sta>1) if(pro[!ko][sta]>10e-16) sta--; for(int j=sta;j<=end;j++) pro[ko][j]=pro[!ko][j-1]*padd+pro[!ko][j]*psame+pro[!ko][j+1]*psub; double can=0; for(int j=t/2+12500;j<=end;j++) can+=pro[ko][j]; if(can>result) result=can; //std::cout<<std::fixed()<<can<<std::endl; ko=!ko; } std::cout<<std::fixed<<std::setprecision(14)<<result; } |
English