Advertisement
Guest User

Untitled

a guest
Jun 7th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.30 KB | None | 0 0
  1. #include<cmath>
  2. #include<list>
  3.  
  4. ...
  5.  
  6. double prob(int n, int k, double p) {
  7.     std::list<double> buf(n-1,0.0);
  8.     buf.push_back(pow(p,n));
  9.  
  10.     for(int i=n; i<k; i++) {
  11.         buf.push_back(buf.back()+(1-p)*pow(p,n)*(1-buf.front()));
  12.         buf.pop_front();
  13.     }
  14.  
  15.     return buf.back();
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement