fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const double p_suc = 1.0/4;
  5. const double p_fail = 3.0/2000;
  6.  
  7. signed main()
  8. {
  9. int n = 5;
  10. vector<vector<double> > dp(n, vector<double>(n, 0));
  11. for(int i=1;i<n;++i){
  12. dp[0][i] = 1.0;
  13. }
  14. for(int i=1;i<n;++i){
  15. for(int j=1;j<n;++j){
  16. dp[i][j] = (p_suc*dp[i-1][j] + p_fail * dp[i][j-1]) / (p_suc+p_fail);
  17. }
  18. }
  19. for(int i=1;i<n;++i){
  20. cout << i << " : " << setw(12) << 1.0 - dp[i][i] << " " << 1000*(1.0 - dp[i][i]) << "\n";
  21. }
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
1 :   0.00596421 5.96421
2 :  0.000106291 0.106291
3 :  2.10265e-06 0.00210265
4 :  4.36567e-08 4.36567e-05