Advertisement
_rashed

UVA 12457

Jun 28th, 2022
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #define ll long long
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4.  
  5. const int OO = 1e9;
  6. const double EPS = 1e-9;
  7. int n;
  8. double p;
  9. double mem[26][26];
  10.  
  11. double solve(int a, int b) {
  12.     if(a == n) {
  13.         return 1;
  14.     }
  15.     if(b == n) {
  16.         return 0;
  17.     }
  18.     if(mem[a][b] != -1) {
  19.         return mem[a][b];
  20.     }
  21.     double &ret = mem[a][b];
  22.     ret = p*solve(a+1,b) + (1-p)*solve(a,b+1);
  23.     return ret;
  24. }
  25.  
  26. int main()
  27. {
  28.     ios_base::sync_with_stdio(false);
  29.     cin.tie(NULL);
  30.     cout.tie(NULL);
  31.     cout.precision(2);
  32.     cout << fixed;
  33.     int t;
  34.     cin >> t;
  35.     while(t--) {
  36.         for(int i = 0; i < 26; i++) {
  37.             for(int j = 0; j < 26; j++) {
  38.                 mem[i][j] = -1;
  39.             }
  40.         }
  41.         cin >> n >> p;
  42.         cout << solve(0,0) << "\n";
  43.     }
  44.  
  45.     return 0;
  46. }
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement