Advertisement
_rashed

SRM339-D1-500

Jun 27th, 2022
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 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.  
  8. class TestBettingStrategy {
  9. public:
  10.     int goal;
  11.     double p;
  12.     double mem[1001][51][11];
  13.     double solve(int money, int rounds, int cb) {
  14.         int bet = (1 << cb);
  15.         if(money >= goal) {
  16.             return 1;
  17.         }
  18.         if(rounds == 0 || bet > money) {
  19.             return 0;
  20.         }
  21.         if(mem[money][rounds][cb] != -1) {
  22.             return mem[money][rounds][cb];
  23.         }
  24.         double &ret = mem[money][rounds][cb];
  25.         ret = p*solve(min(1000,money+bet),rounds-1,0) + (1-p)*solve(max(0,money-bet),rounds-1,cb+1);
  26.         return ret;
  27.  
  28.     }
  29.  
  30.     double winProbability(int initSum, int goalSum, int rounds, int prob) {
  31.         goal = goalSum;
  32.         p = prob/100.0;
  33.         for(int i = 0; i <= 1000; i++) {
  34.             for(int j = 0; j <= rounds; j++) {
  35.                 for(int k = 0; k <= 10; k++) {
  36.                     mem[i][j][k] = -1;
  37.                 }
  38.             }
  39.         }
  40.         return solve(initSum, rounds, 0);
  41.     }
  42. };
  43.  
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement