fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define nmax 3001
  5. double p[nmax] , p1[nmax];
  6. ll n;
  7. bool visited[nmax][nmax];
  8. double dp[nmax][3005];
  9. double tinh(int index , int ch){
  10. if (index == n + 1){
  11. int ct = n- ch;
  12. return(ch > ct and ch <= n)? 1.0 : 0.0;
  13. }
  14. if (visited[index][ch]) return dp[index][ch];
  15. visited[index][ch] = true;
  16. double ans = 0;
  17. ans+= p[index] * tinh(index + 1 , ch + 1);
  18. ans+= p1[index] *tinh(index + 1 , ch);
  19. return dp[index][ch] = ans;
  20. }
  21. void solve(){
  22. memset(dp , -1 , sizeof(dp));
  23. cin >> n;
  24. for (int i = 1 ; i <= n ; i++){
  25. cin >> p[i];
  26. p1[i] = 1.0 - p[i];
  27. }
  28. cout << fixed << setprecision(10) << tinh(1 , 0);
  29. }
  30. int main(){
  31. solve();
  32. }
  33.  
Success #stdin #stdout 0.02s 74464KB
stdin
Standard input is empty
stdout
0.0000000000