Problem p03168 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define FASTIO                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define ll double
#define vi vector<ll>
#define all(a) (a).begin(), (a).end()
#define rep(i, a, b) for (int i = a; i < b; i++)
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define pb push_back
#define endl "\n"
const int MAX = 30 + 3;
// const int  mod=1e9+7;
int n;
vi v(MAX);

double dp[MAX][MAX];
/*
ll fun(int i,int  k)
{
    if(i==n && k<=n/2)
        return 0;
    if(i==n && k>n/2)
        return 1;
       if(dp[i][k]>=0)
       return dp[i][k];
   ll a=v[i]*fun(i+1,k+1);
    ll b=(1-v[i])*fun(i+1,k);
    dp[i][k]=a+b;
    //cout<<a+b<<endl;;
    return a+b;
}*/
ll fun() {
  memset(dp, 0.0, sizeof(dp));
  dp[0][0] = 1.0;
  for (int i = 1; i <= n; i++) {
    dp[i][0] = (1 - v[i - 1]) * dp[i - 1][0];
  }
  for (int i = 1; i <= n; i++) {
    dp[i][i] = (v[i - 1]) * dp[i - 1][i - 1];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < i; j++) {
      dp[i][j] =
          (dp[i - 1][j - 1] * v[i - 1]) + (dp[i - 1][j] * (1 - v[i - 1]));
    }
  }
  /* rep(i,0,n+1)
   {
       rep(j,0,n+1)
       {
           cout<<dp[i][j]<<" ";
       }
       cout<<endl;
   }*/
  double ans = 0.0;
  for (int i = (n / 2) + 1; i <= n; i++)
    ans += dp[n][i];
  return ans;
}
int main() {
  FASTIO

  cin >> n;
  rep(i, 0, n) cin >> v[i];

  double ans = fun();
  cout << fixed << setprecision(12) << ans;
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define FASTIO                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define ll double
#define vi vector<ll>
#define all(a) (a).begin(), (a).end()
#define rep(i, a, b) for (int i = a; i < b; i++)
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define pb push_back
#define endl "\n"
const int MAX = 3000 + 3;
// const int  mod=1e9+7;
int n;
vi v(MAX);

double dp[MAX][MAX];
/*
ll fun(int i,int  k)
{
    if(i==n && k<=n/2)
        return 0;
    if(i==n && k>n/2)
        return 1;
       if(dp[i][k]>=0)
       return dp[i][k];
   ll a=v[i]*fun(i+1,k+1);
    ll b=(1-v[i])*fun(i+1,k);
    dp[i][k]=a+b;
    //cout<<a+b<<endl;;
    return a+b;
}*/
ll fun() {
  memset(dp, 0.0, sizeof(dp));
  dp[0][0] = 1.0;
  for (int i = 1; i <= n; i++) {
    dp[i][0] = (1 - v[i - 1]) * dp[i - 1][0];
  }
  for (int i = 1; i <= n; i++) {
    dp[i][i] = (v[i - 1]) * dp[i - 1][i - 1];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < i; j++) {
      dp[i][j] =
          (dp[i - 1][j - 1] * v[i - 1]) + (dp[i - 1][j] * (1 - v[i - 1]));
    }
  }
  /* rep(i,0,n+1)
   {
       rep(j,0,n+1)
       {
           cout<<dp[i][j]<<" ";
       }
       cout<<endl;
   }*/
  double ans = 0.0;
  for (int i = (n / 2) + 1; i <= n; i++)
    ans += dp[n][i];
  return ans;
}
int main() {
  FASTIO

  cin >> n;
  rep(i, 0, n) cin >> v[i];

  double ans = fun();
  cout << fixed << setprecision(12) << ans;
  return 0;
}