Problem p03168 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long
#define pb push_back
#define vi vector<ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define rs(v, n) v.resize(n)
#define hell 1000000007
#define peak 9123372036854775807
#define pii acos(-1)
#define clr(a, x) memset(a, x, sizeof(a))
#define ios                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ordered_set                                                            \
  tree<ll int, null_type, less<ll int>, rb_tree_tag,                           \
       tree_order_statistics_node_update>
using namespace std;
template <class x, class y> x sum(x a, y b) { return a + b; }
template <class x, class y> x mul(x a, y b) { return a * b; }
template <class x, class y> x sub(x a, y b) { return a - b; }
template <class x, class y> x divi(x a, y b) { return a / b; }

template <class x, class y> istream &operator>>(istream &in, pair<x, y> &p) {
  in >> p.F >> p.S;
  return in;
}
template <class x> istream &operator>>(istream &in, vector<x> &v) {
  for (auto &i : v)
    in >> i;
  return in;
}
template <class x, class y> ostream &operator<<(ostream &out, pair<x, y> &p) {
  out << "(" << p.F << "," << p.S << ") ";
  return out;
}
template <class x> ostream &operator<<(ostream &out, vector<x> &v) {
  out << v.size() << endl;
  for (auto i : v)
    out << i << " ";
  out << endl;
  return out;
}
#define N 1000005

int main() {
  ios;
  ll tt = 1;
  // cin>>tt;
  while (tt--) {
    ll i, j, k, l, m, n;
    cin >> n;
    vector<double> v(n);
    cin >> v;
    double dp[30][30];
    clr(dp, 0);
    dp[0][0] = 1 - v[0];
    dp[0][1] = v[0];
    for (i = 1; i < n; i++) {
      dp[i][0] = dp[i - 1][0] * (1 - v[i]);
      for (j = 1; j <= i + 1; j++) {
        dp[i][j] = dp[i - 1][j] * (1 - v[i]);
        dp[i][j] += dp[i - 1][j - 1] * (v[i]);
        // cout<<dp[i][j]<<" ";
      }
      // cout<<endl;
    }
    double ans;

    for (i = (n + 1) / 2; i <= n; i++) {
      ans += dp[n - 1][i];
    }
    cout << setprecision(10) << ans;
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long
#define pb push_back
#define vi vector<ll int>
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define rs(v, n) v.resize(n)
#define hell 1000000007
#define peak 9123372036854775807
#define pii acos(-1)
#define clr(a, x) memset(a, x, sizeof(a))
#define ios                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);
#define ordered_set                                                            \
  tree<ll int, null_type, less<ll int>, rb_tree_tag,                           \
       tree_order_statistics_node_update>
using namespace std;
template <class x, class y> x sum(x a, y b) { return a + b; }
template <class x, class y> x mul(x a, y b) { return a * b; }
template <class x, class y> x sub(x a, y b) { return a - b; }
template <class x, class y> x divi(x a, y b) { return a / b; }

template <class x, class y> istream &operator>>(istream &in, pair<x, y> &p) {
  in >> p.F >> p.S;
  return in;
}
template <class x> istream &operator>>(istream &in, vector<x> &v) {
  for (auto &i : v)
    in >> i;
  return in;
}
template <class x, class y> ostream &operator<<(ostream &out, pair<x, y> &p) {
  out << "(" << p.F << "," << p.S << ") ";
  return out;
}
template <class x> ostream &operator<<(ostream &out, vector<x> &v) {
  out << v.size() << endl;
  for (auto i : v)
    out << i << " ";
  out << endl;
  return out;
}
#define N 1000005

int main() {
  ios;
  ll tt = 1;
  // cin>>tt;
  while (tt--) {
    ll i, j, k, l, m, n;
    cin >> n;
    vector<double> v(n);
    cin >> v;
    double dp[3000][3000];
    clr(dp, 0);
    dp[0][0] = 1 - v[0];
    dp[0][1] = v[0];
    for (i = 1; i < n; i++) {
      dp[i][0] = dp[i - 1][0] * (1 - v[i]);
      for (j = 1; j <= i + 1; j++) {
        dp[i][j] = dp[i - 1][j] * (1 - v[i]);
        dp[i][j] += dp[i - 1][j - 1] * (v[i]);
        // cout<<dp[i][j]<<" ";
      }
      // cout<<endl;
    }
    double ans;

    for (i = (n + 1) / 2; i <= n; i++) {
      ans += dp[n - 1][i];
    }
    cout << setprecision(10) << ans;
  }
  return 0;
}