dpI - Coins
28 Jan 2021 — Tags: None
Click to show code.
using namespace std;
const int NMAX = 3e3 + 11;
int n;
double p[NMAX], dp[NMAX][NMAX];
double solve(void)
{
dp[0][0] = 1;
for (int i = 1; i <= n; ++i)
dp[0][i] = 0;
for (int i = 1; i <= n; ++i)
{
for (int j = 0; j <= n; ++j)
{
dp[i][j] = (1 - p[i]) * dp[i - 1][j];
if (j != 0)
dp[i][j] += p[i] * dp[i - 1][j - 1];
}
}
return accumulate(dp[n] + n / 2 + 1, dp[n] + n + 1, 0.0);
}
int main(void)
{
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> p[i];
cout << setprecision(10) << solve() << endl;
return 0;
}