fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. double d[2][50050];
  5. int main() {
  6. int n;
  7. cin >> n;
  8. double p;
  9. cin >> p;
  10. d[1][1] = 1;
  11. for (int i = 2; i <= n; ++i) {
  12. double *from = d[~i & 1];
  13. double *to = d[i & 1];
  14. for (int j = 1; j <= i; ++j) {
  15. to[j] = 1 + from[j] * p + from[j - 1] * (1 - p);
  16. }
  17. }
  18. cout << fixed;
  19. cout.precision(10);
  20. for (int i = 1; i <= n; ++i) {
  21. cout << d[n & 1][i] << '\n';
  22. }
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 4196KB
stdin
5
0.25
stdout
1.3320312500
2.6406250000
3.7734375000
4.2031250000
3.0507812500