Advertisement
Saleh127

Light OJ 1050 / Expected Value

Aug 29th, 2022
958
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.36 KB | None | 0 0
  1. /***
  2.  created: 2022-08-29-01.49.51
  3. ***/
  4.  
  5. #include <bits/stdc++.h>
  6. #include <ext/pb_ds/assoc_container.hpp>
  7. #include <ext/pb_ds/tree_policy.hpp>
  8. using namespace std;
  9. using namespace __gnu_pbds;
  10. template<typename U> using ordered_set=tree<U, null_type,less<U>,rb_tree_tag,tree_order_statistics_node_update>;
  11. #define ll long long
  12. #define test int tt; cin>>tt; for(int cs=1;cs<=tt;cs++)
  13. #define get_lost_idiot return 0
  14. #define nl '\n'
  15.  
  16. double dp[2][501][501];
  17. bool v[2][501][501];
  18.  
  19. double solve(ll r,ll b,ll c)
  20. {
  21.     if(r==0 && b==1) return 1.00;
  22.     if(v[c][r][b]) return dp[c][r][b];
  23.  
  24.     double ans=0.00;
  25.  
  26.     v[c][r][b]=1;
  27.  
  28.     if(!c)
  29.     {
  30.         if(r)
  31.         {
  32.             ans+=((1.00*r)/((r+b)*1.00))*solve(r-1,b,c^1);
  33.         }
  34.         if(b)
  35.         {
  36.             ans+=((1.00*b)/((r+b)*1.00))*solve(r,b-1,c^1);
  37.         }
  38.     }
  39.     else
  40.     {
  41.         if(b)
  42.         {
  43.             ans+= /*((1.00*b)/((r+b)*1.00))* */ solve(r,b-1,c^1);
  44.             // this can't contribute to my winning probability
  45.         }
  46.     }
  47.  
  48.     return dp[c][r][b]=ans;
  49. }
  50.  
  51. int main()
  52. {
  53.     ios_base::sync_with_stdio(0);
  54.     cin.tie(0);
  55.     cout.tie(0);
  56.  
  57.     test
  58.     {
  59.         ll r,b;
  60.  
  61.         cin>>r>>b;
  62.  
  63.         //memset(v,0,sizeof v);
  64.  
  65.         cout<<"Case "<<cs<<": "<<fixed<<setprecision(12)<<solve(r,b,0)<<nl;
  66.     }
  67.  
  68.     get_lost_idiot;
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement