#include <stdio.h>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
int main() {
int n, t;
scanf("%d %d", &n, &t);
vector<long double> a(n), p(n+n+1), e(n+n+1);
p[0]=1.;
for (int i = 0; i < n; i++) scanf("%Lf", &a[i]);
sort(a.begin(), a.end());
reverse(a.begin(), a.end());
long double ret = 0;
for (int k = 0; k < n; k++) {
long double x = 0;
e[0] = e[1] = 0;
for (int i = 0; i <= k+k; i++) {
e[i+2] = a[k] * p[i];
e[i] += (1.L-a[k]) * p[i];
p[i] = e[i];
if (i > t+k) x += p[i];
}
p[k+k+1] = e[k+k+1];
if (k+1 > t) x += p[k+k+1];
p[k+k+2] = e[k+k+2];
if (k+2 > t) x += p[k+k+2];
ret = std::max(ret, x);
}
printf("%.7Lf\n", ret);
return 0;
}
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 | #include <stdio.h> #include <vector> #include <algorithm> #include <utility> using namespace std; int main() { int n, t; scanf("%d %d", &n, &t); vector<long double> a(n), p(n+n+1), e(n+n+1); p[0]=1.; for (int i = 0; i < n; i++) scanf("%Lf", &a[i]); sort(a.begin(), a.end()); reverse(a.begin(), a.end()); long double ret = 0; for (int k = 0; k < n; k++) { long double x = 0; e[0] = e[1] = 0; for (int i = 0; i <= k+k; i++) { e[i+2] = a[k] * p[i]; e[i] += (1.L-a[k]) * p[i]; p[i] = e[i]; if (i > t+k) x += p[i]; } p[k+k+1] = e[k+k+1]; if (k+1 > t) x += p[k+k+1]; p[k+k+2] = e[k+k+2]; if (k+2 > t) x += p[k+k+2]; ret = std::max(ret, x); } printf("%.7Lf\n", ret); return 0; } |
English