Problem p03168 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define ff first
#define ss second
#define END "\n"
#define pb push_back
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = 1 << 29;
typedef long long ll;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<ii> vii;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int &n, int b) { n |= two(b); }
inline void unset_bit(int &n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) {
  int res = 0;
  while (n && ++res)
    n -= n & (-n);
  return res;
}
template <class T> void chmax(T &a, const T &b) { a = max(a, b); }
template <class T> void chmin(T &a, const T &b) { a = min(a, b); }
/////////////////////////////////////////////////////////////////////
int main() {
  fast int n, i, j;
  long double p[3000], ans = 0;
  long double dp[300][300] = {0};
  cin >> n;
  dp[0][0] = 1;
  dp[0][1] = 0;
  for (i = 1; i <= n; i++) {
    cin >> p[i];
    dp[i][0] = dp[i - 1][0] * (1 - p[i]);
  }
  // for (i = 0; i < n; i++)
  // cout << p[i] << " ";
  for (i = 0; i <= n; i++) {
    for (j = 1; j <= i; j++) {
      dp[i][j] = p[i] * dp[i - 1][j - 1] + (1 - p[i]) * dp[i - 1][j];
    }
  }
  // for (i = 0; i <= n; i++)
  // {
  //     for (j = 0; j <= n; j++)
  //     {
  //         cout << dp[i][j] << " ";
  //     }
  //     cout << END;
  // }
  for (i = 0; i <= n; i++) {
    if (i > (n / 2)) {
      ans += dp[n][i];
    }
  }
  cout << setprecision(10);
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define ff first
#define ss second
#define END "\n"
#define pb push_back
#define fast                                                                   \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = 1 << 29;
typedef long long ll;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<ii> vii;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int &n, int b) { n |= two(b); }
inline void unset_bit(int &n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) {
  int res = 0;
  while (n && ++res)
    n -= n & (-n);
  return res;
}
template <class T> void chmax(T &a, const T &b) { a = max(a, b); }
template <class T> void chmin(T &a, const T &b) { a = min(a, b); }
/////////////////////////////////////////////////////////////////////
int main() {
  fast int n, i, j;
  long double p[3000], ans = 0;
  long double dp[3000][3000] = {0};
  cin >> n;
  dp[0][0] = 1;
  dp[0][1] = 0;
  for (i = 1; i <= n; i++) {
    cin >> p[i];
    dp[i][0] = dp[i - 1][0] * (1 - p[i]);
  }
  // for (i = 0; i < n; i++)
  // cout << p[i] << " ";
  for (i = 0; i <= n; i++) {
    for (j = 1; j <= i; j++) {
      dp[i][j] = p[i] * dp[i - 1][j - 1] + (1 - p[i]) * dp[i - 1][j];
    }
  }
  // for (i = 0; i <= n; i++)
  // {
  //     for (j = 0; j <= n; j++)
  //     {
  //         cout << dp[i][j] << " ";
  //     }
  //     cout << END;
  // }
  for (i = 0; i <= n; i++) {
    if (i > (n / 2)) {
      ans += dp[n][i];
    }
  }
  cout << setprecision(10);
  cout << ans << endl;
  return 0;
}