fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef vector<bool> vb;
  5. typedef vector<vb> vvb;
  6. typedef vector<int> vi;
  7. typedef vector<vi> vvi;
  8. typedef vector<ll> vl;
  9. typedef vector<vl> vvl;
  10. typedef vector<char> vc;
  11. typedef vector<vc> vvc ;
  12. typedef vector<string> vs;
  13. typedef vector<pair<ll, ll> > vp;
  14. typedef pair<ll, ll> pl;
  15.  
  16. #define endl "\n"
  17. #define pb push_back
  18. #define F first
  19. #define S second
  20. #define all(v) v.begin(), v.end()
  21. #define rall(v) v.rbegin(), v.rend()
  22. #define sz(a) int(a.size())
  23. const ll mod = 1e9+7;
  24.  
  25. ll n;
  26. long double dp[3001][3001];
  27. vector<long double> v;
  28.  
  29. long double f(ll x, ll o){
  30. if(x>=n) {
  31. if(o>=(n+1)/2){
  32. return 1;
  33.  
  34. } else {
  35. return 0;
  36. }
  37. }
  38.  
  39. if(dp[x][o]!=-1)
  40. return dp[x][o];
  41.  
  42. dp[x][o]=v[x] * f(x+1, o+1) + (1-v[x]) * f(x+1, o);
  43.  
  44. return dp[x][o];
  45. }
  46.  
  47. void solve(){
  48. long double aux;
  49. cin >> n;
  50. for(ll i=0; i<n; i++){
  51. cin >> aux;
  52. v.pb(aux);
  53. }
  54.  
  55. for(ll i=0; i<n; i++){
  56. for(ll j=0; j<n; j++){
  57. dp[i][j]=-1;
  58. }
  59. }
  60.  
  61. std::cout << std::fixed << std::setprecision(10);
  62. cout << f(0, 0) << endl;
  63.  
  64. }
  65.  
  66. int main(){
  67. ios::sync_with_stdio(false);
  68. cin.tie(nullptr);
  69.  
  70. int tt=1;
  71.  
  72. // cin >> tt;
  73.  
  74. while(tt--){
  75. solve();
  76. }
  77. }
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
1.0000000000